Python3 is becoming more and more accepted by developers, and embarrassingly many legacy systems still run Python2, so sometimes you have to develop and debug in both versions at the same time.

Python2 and Python3 coexist in a system is a problem developers have to face, and the good news is that Anaconda is a perfect solution to the Python2 and Python3 coexistence problem, The common failure to install dependencies (such as mysql-Python) on The Windows platform has also been addressed.

What is Anaconda?

Anaconda is a distribution of Python. If Python is compared to Linux, Anancoda is CentOS or Ubuntu. It addresses two major pain points for Python developers.

  • First: package management, functionality similar to PIP, Windows platform installation of third-party packages often failed to solve the scenario.

  • Second: provides virtual environment management, which is similar to virtualEnv and solves the problem of multiple Python versions.

Download the Anaconda

Directly on the website to download the latest version of the www.continuum.io/downloads installation package, choose Python3.6 version of the installation package, installed directly after the download is complete, the installation process, select the default configuration is about 1.8 G of disk space.

Conda is a command line tool for package management and environment management under Anaconda. It is a combination of PIP and Vitualenv. After the installation is successful, conda is added to environment variables by default. Therefore, you can directly run the conda command on the CLI

If you are familiar with VirtualEnv, it is very easy to get started with Conda. If you are not familiar with Virtulenv, it provides a few simple commands. We can use conda’s virtual environment management capabilities to switch freely between Python2 and Python3.

Multi-version Switching

Conda create --name test_py3 python=3.6 conda create --name test_py3 python=3.6 --name test_py2 python=2.7 # activate test_py2 # Windows source activate test_py2 # Linux/MAC # switch to PYTHon3 activate test_py3Copy the code

For more commands, see help conda -h

Package management tool

Conda’s package management capability complements PIP and allows you to start installing third-party packages in a Python environment that is already active.

Conda install matplotlib conda install matplotlib conda install matplotlib conda install matplotlib matplotlibCopy the code

For modules that can’t be successfully installed with PIP, you can try using Conda. If you can’t find the corresponding package with Conda, you can still use PIP to install the package.

Increase download speed

The default Anaconda mirror address is in a foreign country, which will be slow when using conda installation package. Currently, the 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: trueCopy the code

In addition, you can also change the source address of PIP mirror into domestic, douban source speed is relatively fast. Change ~/.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/simpleCopy the code

I didn’t expect to update it over the weekend. I will continue to write crawler series in the next article. Go ing


Python Zen (ID: VTTalk) shares technical know-how and the occasional small talk