Python3 is accepted by more and more developers, and it is embarrassing that many legacy systems are still running in the Python2 environment, so sometimes you have to develop and debug in two versions at the same time.
How to coexist Python2 and Python3 in the system at the same time is a problem that developers have to face. The good news is that Anaconda can perfectly solve the coexistence problem of Python2 and Python3, and the installation of dependent packages (such as MySQL-python) often occurs on the Windows platform. ) failures are also resolved.
What is Anaconda?
Anaconda is a distribution of Python. If Python is compared to Linux, then Anancoda is CentOS or Ubuntu. It addresses two major pain points for Python developers.
- First: Provide package management, which is similar to pip, and solves the problem that third-party packages often fail to be installed on the Windows platform.
- Second: Provide virtual environment management, similar to virtualenv, and solve the problem of coexistence of multiple versions of Python.
Download Anaconda
Download the latest version of the https://www.continuum.io/downloads installation package directly from the official website , select the Python 3.6 version installation package, and install it directly after the download is complete. You can choose the default configuration during the installation process, which requires about 1.8G of disk. space.
conda
It is a command-line tool for package management and environment management under Anaconda, a combination of pip and vitualenv. After the installation is successful, conda will be added to the environment variable by default, so you can run the conda command directly in the command line window
If you are familiar with virtualenv, it is very easy to get started with conda. It doesn't matter if you are not familiar with virtualenv. It provides only a few commands, which are very simple. We can switch freely between Python2 and Python3 using conda's virtual environment management capabilities.
Multi-version switching
# Create an environment named test_py3 based on python3.6 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 # windows source activate test_py2 # linux/mac # switch to python3 activate test_py3
For more commands, see help conda -h
package management tool
The package management function of conda is a supplement to pip. If a Python environment is currently activated, third-party packages can be installed in the current environment.
# install matplotlib conda install matplotlib # View installed packages conda list # package update conda update matplotlib # delete package conda remove matplotlib
For those modules that cannot be installed successfully with pip, you can try to install them with conda. If you cannot find the corresponding package with conda, of course, you can continue to choose pip to install the package.
Increase download speed
The mirror address of Anaconda is abroad by default, and it will be very slow when using conda to install the package. The currently available domestic mirror source address is provided by Tsinghua University. Modify ~/.condarc (Linux/Mac) or C:\Users\current username.condarc (Windows) configuration
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - defaults show_channel_urls: true
In addition, you can also change the mirror source address of pip to a domestic one. Douban source is faster. Modify ~/.pip/pip.conf (Linux/Mac) or C:\Users\current username\pip\pip.ini (Windows) configuration:
[global] trusted-host = pypi.douban.com index-url = http://pypi.douban.com/simple