Use pyenv and vtualenv for environmental isolation, use jupyter to facilitate our learning
New user
All operations should be done in a separate user, not using the root user
useradd python
PYENV installation Pyenv
Isolation of the development version and the package version used
GitHub Address
The installation process is performed in CentOS, with the Epel source in mind
Install Git
yum install git -y
Installation dependencies
yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel
Upgrade NSS, while ensuring that the system time is correct, or install pyenv may error
yum update nss
Installing Pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
Add the following three lines to the ~/.bash_profile
export PATH="/home/python/.pyenv/bin:$PATH"eval "$(pyenv init -)"eval "$(pyenv virtualenv-init -)"
source ~/.bash_profile
This way, when the user starts, it executes the user's. Bash_profile in the footsteps, will start the pyenv
The installed pyenv is in the ~/.pyenv.
Use of pyenv
List all available versions
pyenv instll --list
Install the specified version online (plus-V to see the detailed installation process)
pyenv install 3.5.3 -v
View all installed versions (System is a version of current systems)
pyenv versions
This installs slowly, in order to speed up, uses the cache method installs
In the ~/.pyenv directory, create a new cache directory and put the downloaded version of the file, such as Python-3.6.3.tar.xz
pyenv install 3.6.3 -v
Python version control for pyenv
Version shows the current Python version
Versions displays all installed Python versions, and the current version
Global Settings
$ pyenv global 3.5.3
You can see that all the Windows under PYENV control are 3.5.3 python versions.
Here with Global is acting on the non-root user python user, if the root user installation, do not use global, otherwise the impact is too large.
For example, CentOS is the use of Python2.x,root users under the use of global 3.X, will bring bad impact
Adjust back to system default version
$ pyenv global system
Shell Session Settings
Impact only works on current session
$ pyenv shell 3.6.2
Local Settings
Use the Pyenv local setting to inherit this setting from the current working directory, starting with the downward recursion
pyenv local 3.6.2
Virtualenv Virtual Environments
Why use a virtual environment?
Because the Python environment you just used is a public space, if multiple projects are developed using a different Python version, or run with a different version of Python, or are developed using the same version but different projects use different versions of the library, these problems can be a conflict. The best solution is for each project to run its own "isolated small environment" independently of each other.
We create a new directory and then switch this directory to the Python 3.6.2 environment, which does not conflict with the 2.x environment that comes with the system
mkdir -p dzm/projects/test/
Create a virtual environment, use Python 3.6. Version 2 to create a separate virtual space
pyenv virtualenv 3.6.2 py362
You can now use PYENV versions to see the environment named py362 in the version list
To switch a new directory to a py362 environment
cd dzm/projects/test/pyenv local py362
The python environment below the current directory and its subdirectories becomes 3.6. Version 2
Other
Real-world catalogs for different environments
/home/python/.pyenv/versions/
The packages installed in each environment will be in the appropriate site-packages directory.
/home/python/.pyenv/versions/3.6.2/lib/python3.6/site-packages
Installing Ipython
Ipython is an enhanced interactive Python command-line tool
The operation is still in the dzm/projects/test/directory, where Ipython is also installed in this environment, isolated from the outside environment
pip install ipythonipython
PIP General Configuration
Pip is Python's package management tool, 3.x version directly with, you can directly use
Like Yum. To use the domestic image, do the following configuration
Linux Systems
$ mkdir ~/.pipvim ~/.pip/pip.conf
[global]index-url=https://mirrors.aliyun.com/pypi/simple/truste
Windows system
Pip config file New pip folder in home directory, create new text file Pip.ini inside, equivalent to pip.conf of Linux environment
PIP Other applications
See which packages are installed in the current environment
pip list
Export the list of packages for the current environment to a file
pip freeze > requirement
Install packages based on the list exported above
pip install -r requirement
(You can also copy files from the virtual Environment package directory directly into the new environment Package directory.)
Jupyter installation Jupyter
is a web-based, interactive notebook that makes it very easy to use Python
Installing the Jupyter will also install the Ipython
pip install jupyter
View Help
jupyter notebook --help
Set a password (otherwise you will enter a random password at startup when browsing with the web)
jupyter notebook password
Boot (if not custom 0.0.0.0, then the default binding 127.0.0.1 after startup, external is not browsable, the default 8888 port)
jupyter notebook --ip=0.0.0.0
Viewing the boot port (default 8888)
ss -tanl
View native IP Address
Browse ip:8888 via browser in Windows system, enter password to use Jupyter
Installing PYENV, vtualenv virtual environments, and Jupyter in Linux environments