Python multi-version multi-environment introduction under Linux

Source: Internet
Author: User
Tags rehash virtualenv

One, Python multi-version configuration instructions

Installing Python-dependent dependencies

[[Email protected] ~] # Yum install-y gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel

Installing the Git tool

[[Email protected] ~] # Yum install-y git

Create a Python user

[[Email protected] ~] # Useradd python

Switch to a Python user

[[Email protected] ~] # Su-python

Pull the pyenv script from GitHub and execute

[Email protected] ~]$ curl-l Https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer|bash

Load pyenv automatically by adding
# The following to ~/.bash_profile:

By adding the following to the Python user's ~/.bash_profile file Finally, make pyenv automatically load

Export path="/home/python/.pyenv/bin: $PATH""$ (pyenv init-) "  "$ (pyenv virtualenv-init-)"

Make the added content effective

[Email protected] ~]$ source ~/.bash_profile

Command-line execution can get pyenv related command description

[[Email protected] ~]$ pyenv pyenv1.1.5usage:pyenv<command> [<args>]some Useful pyenv commands are:commands List all available pyenv commands local SetorShow The local application-Specific Python versionGlobalSetorShow theGlobalPython version Shell SetorShow the shell-specific Python version install install a python version using Python-Build Uninstall Uninstall a specific Python version rehash rehash pyenv shims (run this after installing ex Ecutables) version Show the current Python version andIts origin versions List all Python versions available to pyenv which Display the full path to an execut Able whence List All Python versions this contain the given Executablesee ' pyenv Help<command>'For information on a specific command.For full documentation, SEE:HTTPS://GITHUB.COM/PYENV/PYENV#Readme

You can install multiple versions of Python and then switch

View current Python version

[[email protected] ~]$ python-2.6.6

List all available versions

[Email protected] ~]$ pyenv install-l

Install the specified version

[Email protected] ~]$ pyenv install 3.6.3-v

Note:

When this kind of online installation is too slow, you can choose to use the cache installation, that is, to install the corresponding source package, put in the/home/python/.pyenv/cache directory, the cache directory does not exist when created.

[Email protected] ~]$ mkdir-p/home/python/.pyenv/~]$ ll/home/python/.pyenv/cache/38724- rw-r--r--1 python python 16974296 Nov 10:19 Python-3.6.3tar.xz-rw-r--r--1 python python 22673115 17 10: Python-3.6.3~]$ pyenv Install 3.6.3-v

After the installation is complete, look at the python version (the python version with * Code currently in effect, system is the default version, this is python2.6.6)

[[Email protected] ~]$ pyenv Versions* System (set by/home/python/.pyenv/version)  3.6.3

Toggle to set Python version, general recommended with Python Local settings

Pyenv Global 3.6.3
Note: Under Root, try not to apply global and change the Python version

Pyenv Shell 3.6.3
Acts on the current session only

Python local 3.6.3
Setting inherits this setting recursively from the current working directory

This demonstrates the functionality of Python local

[Email protected] ~]$ mkdir test#Create a new test directory in your home directory[[Email protected] ~]$ lltotal4DRWXRWXR-X 2 python python 4096 Nov 17 18:28Test[[email protected]~]$ CD test/#switch to the test directory[Email protected] test]$ pyenv local 3.6.3[email protected] test]$ pyenv versions System* 3.6.3 (Set by/home/python/test/.python-version) [[email protected] test]$ python-V#this should be a bug, re-login or normal.Python 2.6.6[[email protected] test]$ python-V Python3.6.3#Enter the subdirectory of test and also inherit the Python version settings[[email protected] test]$ mkdir child[[email protected] test]$ CD child/[email protected] child]$ pyenv versions System* 3.6.3 (Set by/home/python/test/.python-version) [[email protected] child]$ python-Vpython3.6.3
#go to another directory, Python version is the system default version[[Email protected] ~]$ pyenv versions* System (Set by/home/python/.pyenv/version)3.6.3[[Email protected]~]$ Python-Vpython2.6.6

Ii. Python Multi-environment configuration instructions

Create a 3.6.3 version of the standalone space environment

[Email protected] ~]$ pyenv virtualenv 3.6.3 Martin#the last name of the space, I arbitrarily specifyRequirement already satisfied:setuptoolsinch/home/python/.pyenv/versions/3.6.3/envs/martin/lib/python3.6/site-Packagesrequirement already Satisfied:pipinch/home/python/.pyenv/versions/3.6.3/envs/martin/lib/python3.6/site-Packages[[email protected]~]$ pyenv Versions#View all versions of Python installed* System (Set by/home/python/.pyenv/version)3.6.3 3.6.3/envs/Martin Martin[[email protected]~]$ CD test/[email protected] test]$ Pyenv local Martin#set the Python version of the current directory(Martin) [Email protected] test]$ pyenv versions#View the default version after switching, after setting up the standalone space environment, the command prompt will be preceded by the name of a separate space set by itself .system3.6.3 3.6.3/envs/Martin* Martin (set by/home/python/test/.python-version)

After the isolated space is configured, the installed package exists in a separate directory

(Martin) [Email protected] test]$ pip- from/home/python/.pyenv/versions/3.6.3/envs/martin/lib/python3.6/ Site-packages (Python 3.6)    # Standalone space package exists in this directory

Virtualenv plug-in, plugins/pyevn-virtualenv
Create a 3.6.3 version of the standalone space
Pyenv virtualenv 3.6.3 Martin
Pyenv Local Martin

Python multi-version multi-environment introduction under Linux

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.