Operating system preparation
Get ready Linux The minimum system is enough .
If you clone in a virtual machine ,MAC The address will change .
Use here CentOS 6.5+
install
1, First of all, safety git
yum install git -y
2, install Python Environment depends on
yum -y install git gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel
3, establish python user
useradd python
4、 Use python Install after user login Pyenv
$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
Download the pyenv-installer It's a shell Script . Be careful :
- stay https://github.com/pyenv/pyenv-installer There are installation documents
- If curl appear curl: (35) SSL connect error , yes nss The problem of low version , Update it . You may need to configure a new package yum Source , Here is /etc/yum.repo/ Add a source , And then update
[updates]
name=CentOS-Updates
baseurl=https://mirrors.aliyun.com/centos/6.9/os/x86_64
gpgcheck=0
And then update nss
yum update nss
5、 stay python User ~/.bash_profile Middle append
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
$ source ~/.bash_profile
So when the user starts , Will execute the user's .bash_profile The script in the , Will start pyenv. Installed pyenv It's just ~/.pyenv in
Pyenv Use
python Version and path route
$ python --version
$ python -V
$ echo $PATH
You can see the current system Python route
pyenv command
$ pyenv help install
List all available versions
Online installation python3.5.3 edition
$ pyenv versions This installation may be slow , To speed up , But choose cache Method .
Put the manually downloaded installation package in stay ~/.pyenv/cache Under the table of contents
cache The directory is new
Specifically python The version can be downloaded https://www.python.org/ftp/python/3.5.3/
PS: Download from the official website is reliable
pyenv Of python version control
pyenv Provides three ways of version control , With 3.5.3 give an example
pyenv global 3.5.3 global Set the system to 3.5.3 Linux Mostly based on 2.6 and 2.7 edition , Arbitrarily change , The risk factor is very high , Be careful with !!!
pyenv shell 3.5.3 Only valid for the current reply , Once disconnected, it fails
below , It's a pattern we usually use
pyenv local 3.5.3
local Local settings Use pyenv local Settings inherit this setting recursively from the current working directory .
As shown in figure shows ,pyenv You can actually change the current path python edition , But if a version of pip Management is all together , It's not suitable for project separation .
And that's where it comes in pyenv The packet separation function of
Virtualenv Virtual environment settings
Why use a virtual environment ? As mentioned above , If multiple projects use different Python Version development , Or use a different Python Version deployment run , Or use the same version of the library, but different projects use different versions of the library , And so on, these problems can bring conflicts . The best solution is to run each project independently “ Independent environment ” in .
Let's start with 3.5.3 In the version, a virtual small version comes out
pyenv virtualenv 3.5.3 mt353
Can exist in the version list , Just like 3.5.3 It's the same , It's just a version . The real catalog is in ~/.pyenv/versions/ Next , In the future, just use this virtual version , The package will follow the corresponding directory , Instead of using 3.5.3.
Then we set up a directory version
As shown in the figure, execute according to the actual demand pyenv local mt353
It can be seen that the current directory has been loaded mt353 edition
In the future, the related package management will be integrated under this version
pip General configuration
pip yes Python Package management tools ,3.x The version of is directly with , You can use it directly . and yun The same for the use of domestic images , The following configuration .
Linux System $ mkdir ~/.pip Configuration file in ~/.pip/pip.conf
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com
In different virtual environments , install redis package , Use pip list Look at the effect . $ pip -V pip install pkgname command , It is the installation that will be used frequently in the future python The order of the bag
summary
thus , It has been implemented to use pyenv stay Centos 6 The above are python Version control and project separation , Open up the subsequent freedom python project , Any version , Any path ,pip No conflict , Fabulous !