Multi version python import problem solution

Source: Internet
Author: User

Original HTTP://WWW.TUICOOL.COM/ARTICLES/ENE7NM6

Multi-version Python coexistence [Support for PIP installation package] Sometimes the special need to use a high version of Python, but the system comes with the version of a lot of other tools rely on, can not be arbitrarily updated. So you'll consider installing another version of the Python environment, and then use this version to indicate #/usr/bin/env python2.7 in the script header.

# # Download the python version of the source package you want to install (I'm using version 2.7)

Wget ' http://www.python.org/ftp/python/2.7/python-2.7.tar.bz2′

# #标准的安装流程, install python2.7 to/usr/local/python2.7 directory:

TAR-XVF python-2.7.tar.bz2cd Python2.  7./configure–prefix=/usr/local/python2. 7 &&  Make install    

# # Create a python2.7 link that makes it easy to call

ln-sv/usr/local/python2.7/bin/python2.7/usr/bin/python2.7

General requirements You can use python2.7 in this step. However, if you need to install additional packages to python2.7, when installing packages using Easy_install, Pip and other package management tools, you will still be loaded into the system's own version of Python directory. Packages installed under the python2.7 version are also not available for import. Here's how to fix it:

# # Next Install some required package environment (Setuptools, PIP)

wget--no-check-certificate  ' https://pypi.python.org/packages/ Source/s/setuptools/setuptools-0.7.2.tar.gz ' tar-xvf setuptools-0.7. 2.tar.gzCD setuptools-0.7. 2python2. 7 setup. py install–prefix=/usr/local/python2. 7 wget--no-check-certificate  Https://pypi.python.org/packages/source/p/pip/pip-1.2.tar.gz ' tar-xvf pip-1.2.tar.gz< Span class= "Hljs-keyword" >CD pip-1.2python2. 7 Setup. py install–prefix=/usr/local/python2. 7              

# # Create a pip-2.7 link that makes it easy to call

/usr/local/python2.7/bin/pip-2.7/usr/bin/pip-2.7 

Packages installed using the pip-2.7 command are then automatically loaded into the/usr/local/python2.7 corresponding directory. This installs the package not only can import, more importantly does not have the different version compatibility problem (some packages are different under different versions of Python)

Multi version python import problem 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.