Python/anaconda Multi-version coexistence solution

Source: Internet
Author: User
Tags virtualenv jupyter

The articles in the blog are Meelo original, please make sure to indicate the address in the link form

Although Python2 tide, many projects have supported Python3, there are always some tutorials and projects that only support Python2. The usual situation is that the computer is loaded with both Python2 and Python3.

There are a number of solutions for coexistence of multiple Python versions, with a few simple lists:

    • Directly modify the program file name
    • With Pyenv and virtualenv
    • With the Conda environment
    • Using Python Launcher

These methods have their own shortcomings, the direct modification of the program file name still does not solve the problem of the PIP Package Manager, the Jupyter and other scripts do not work; the virtualenv and Conda switching processes are slightly more complex and require a virtual environment to be turned on and off.

Here is a new solution for all Windows and Linux systems, for different versions of Python2 and Python3 for native distributions, and for other distributions Anaconda2 and Anaconda3. Take Windows systems as an example in the tutorial.

The system chooses which Python is based on path system paths.

When executing a program, the system searches the system path for an executable file of the same file name. The presence of a Python version means that there are multiple executable programs whose names are Python, at which point the system chooses which version depends on the path in the order of the system path.

C:\Python27; C:\Python27\Scripts; C:\Users\meelo\Anaconda3; C:\Users\meelo\Anaconda3\Scripts

If the system path is as shown above. Python27 before, the default applicable version is Python2.7.

My solution is taking advantage of this. Here is the dry time.

Step 1: Remove the path to the other Python versions in the system path, leaving only the version that is used by default

Note Python contains two paths in the system path one is the root directory C:\Python27, and the other is the Scripts directory C:\Python27\Scripts

Set the system path you can execute Win-x > System > Advanced system Settings > Environment variables > Edit Path

Step 2: Create a script in the C:\Windows directory

Script Name: Py2.bat, the script name is the command that needs to be executed each time the version is switched.

Script Content

@echo Offset Path=C:\Users\meelo\Anaconda2; C:\Users\meelo\Anaconda2\Scripts;%path%

The purpose of the script is to temporarily add the Python version path that needs to be used to the system path. Note that the system path is temporarily changed so that the other command line (shell) is not affected.

The green part of the script is the path to the Python version that you want to use temporarily. @echo off means that the contents of the output command are not printed when the script is executed.

Step 3: Temporarily switch python versions

-install Seaborn
Py2 & Python-v
Py2 & Pip Install Seaborn
Py2 & Jupyter

Temporarily switching python only needs to precede the original command with Py2 & or execute the command py2 separately before. If you choose to add a py & to the command, only the 1th command needs to be added, and subsequent commands will automatically use the Switched Python version.

Finally, the direct win+r input py2 & python in the runtime, the above method is still in effect.

After studying a lot of methods, I found my method is the simplest. Have any questions welcome message.

Python/anaconda Multi-version coexistence solution

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.