Using Anaconda to perfectly solve the coexistence problem between Python 2 and python 3, anacondapython
Preface
Currently, Python3 is accepted by more and more developers. what's embarrassing is that many legacy systems are still running in the Python2 environment, so sometimes you have to develop them in two versions at the same time, debugging.
In the system, how to coexist with Python2 and Python3 is a problem that developers have to face. A good news is that Anaconda can perfectly solve the coexistence problem of Python2 and Python3, in addition, dependency packages (such as MySQL-python) may often fail to be installed on Windows platforms.
What is Anaconda?
Anaconda is a Python release. If you compare Python to Linux, Anancoda is CentOS or Ubuntu. It solves the two pain points of Python developers.
- 1. Provides package management, which features similar to pip. The installation of third-party packages on Windows platforms often fails.
- Second: provides virtual environment management, which features similar to virtualenv and solves the coexistence of multiple versions of Python.
Download the Anaconda installation package
Official Website:Https://www.continuum.io/downloads
Local:
Anaconda3 4.3.1 Python 3.6 for windows 64-bit: http://www.bkjia.com/softs/556361.html
Anaconda3 4.3.1 Python 3.6 for windows 32-bit: http://www.bkjia.com/softs/556363.html
Anaconda3 4.3.1 Python 3.6 for linux 32-bit: http://www.bkjia.com/softs/556380.html
Anaconda3 4.3.1 Python 3.6 for linux 64-bit: http://www.bkjia.com/softs/556392.html
We select the installation package of Python 3.6. After downloading the package, we can directly install the package. During the installation process, we can select the default configuration, which requires about GB of disk space.
Conda is a command line tool for package management and environment management in Anaconda, and a combination of pip and vitualenv. After the installation is successful, conda is added to the environment variables by default. Therefore, you can directly run the conda command in the command line window.
If you are familiar with virtualenv, it is very easy to get started with conda. It does not matter if you are not familiar with virtulenv. It provides only a few simple commands. We can use the conda virtual environment management function to switch between Python2 and Python3 freely.
Multi-version Switch
# Create an environment named test_py3 conda create -- name test_py3 python = 3.6 # create an environment named test_py2 Based on python2.7 conda create -- name test_py2 python = 2.7 # activate the test environment activate test_py2 # windowssource activate test_py2 # linux/mac # Switch to python3activate test_py3
For more commands, see helpconda -h
Package management tools
The package management function of conda is a supplement to pip. If a Python environment has been activated, you can install a third-party package in the current environment.
# Install matplotlib conda install matplotlib # view the Installed Package conda list # package update conda update matplotlib # Delete package conda remove matplotlib
You can use conda to install modules that cannot be successfully installed with pip. If you cannot find the corresponding package with conda, you can choose pip to install the installation package.
Improves download speed
By default, the image address of Anaconda is abroad and will be slow when you use the conda installation package. Currently, the available domestic image source address is provided by Tsinghua University. Modify ~ /. Condarc (Linux/Mac) or C: \ Users \ current user name. condarc (Windows) Configuration
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - defaultsshow_channel_urls: true
In addition, you can also change the pip Image Source Address to the domestic address, which is faster. Modify ~ /. Pip/pip. conf (Linux/Mac) or C: \ Users \ current USERNAME \ pip. ini (Windows) Configuration:
[global]trusted-host = pypi.douban.comindex-url = http://pypi.douban.com/simple
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message. Thank you for your support.