Python3 and Python2 Virtual environment configuration under Windows

Source: Internet
Author: User
Tags sublime text virtual environment virtualenv install matplotlib

Python3 is accepted by more and more developers, and it is embarrassing that many legacy systems still run in Python2 environments, so sometimes you have to develop and debug in two versions at the same time.

How to coexist Python2 and Python3 in the system is a problem that developers have to face, a good news is that Anaconda can solve the coexistence problem of Python2 and Python3 perfectly, and the installation of dependency packages (such as MySQL) often occurs on the Windows platform. -python) The failure situation is resolved.

What is Anaconda?

Anaconda is a distribution version of Python, and if Python is compared to Linux, then Anancoda is either CentOS or Ubuntu. It solves two big pain points for Python developers.

    • First: Provides package management, features similar to the Pip,windows platform installation third-party packages often failed scenarios are resolved.
    • Second: Provide virtual environment management, function similar to virtualenv, solve multi-version python coexistence problem.
Download Anaconda

Download the latest version of the Https://www.continuum.io/downloads installation package directly on the official website, select the Python3.6 version of the installation package, install it directly after the download is complete, select the default configuration for the installation process, and take approximately 1.8G of disk space.

You can also install smaller miniconda,https://conda.io/miniconda.html.

condaAnaconda is a command-line tool for package management and environment management, and is a combination of Pip and vitualenv. After the installation is successful, Conda is 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, then get started Conda very easy, not familiar with virtulenv, it does not matter, it provides the command on a few, very simple. We can use Conda's virtual environment management function to switch freely between Python2 and Python3.

Creating virtual environments for Python3 and Python2
Conda--create name=venv_py36 python=3.6
Conda--create name=venv_py27 python=2.7

View Virtual Environments

Conda env List

Package Management Tools
The package management feature of Conda is a supplement to pip, and if a Python environment is currently activated, you can start installing a third-party package in your current environment.

# Install Matplotlib
Conda Install Matplotlib
# View Installed Packages
Conda List
# Package Update
Conda Update Matplotlib
# Delete Package
Conda Remove Matplotlib


Configure domestic Anaconda domestic source, improve download speed
Anaconda The mirror address of the default in foreign countries, with Conda installation package will be very slow, the current available domestic mirror source address is provided by Tsinghua University. Modify ~/.condarc (Linux/mac) or Condarc (Windows) configuration

Channels
-Binstar_username
-https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
-Defaults

Proxy_servers:
http:http://proxy.xxx.com:8080
https:https://proxy.xxx.com:8080


C:\Users\ Current user name \pip\pip.ini (Windows) configuration (create a new one without a directory)

[Global]
Trusted-host = pypi.douban.com
Index-url = Http://pypi.douban.com/simple


Configure Sublime

Sublime Configuration using Python3
Open Sublime Text 3, enter Tools-->build system-->new Build System in turn;

{
"cmd": ["C:/users/perry/miniconda3/envs/venv_py36/python.exe", "-U", "$file"],
"File_regex": "^[]*file \" (...) \ ", line ([0-9]*)",
"Selector": "Source.python",
"Encoding": "cp936",
}

Sublime Configuration using Python2
Open Sublime Text 3, enter Tools-->build system-->new Build System in turn;

{
"cmd": ["C:/users/perry/miniconda3/envs/venv_py27/python.exe", "-U", "$file"],
"File_regex": "^[]*file \" (...) \ ", line ([0-9]*)",
"Selector": "Source.python",
"Encoding": "cp936",
}

Note:

1, if not add "encoding": "cp936", this, can not display Chinese;
2, if you use the Simplified Chinese system, encoding must cp936 and not UTF8
3, after the configuration is complete, click Save, you can customize the file name, but you must use the default path, so that the configuration can take effect;

The default is saved in C:\Users\ current user \appdata\roaming\sublime Text 3\packages\user

Python3 and Python2 Virtual environment configuration under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.