Virtual environments:
command to install Python package before: sudo pip3 install package name
Installation path of the package:/usr/local/lib/python3.5/dist-packages
Install different versions of the same package, and the packages that are installed will overwrite the packages that were originally installed. Thus, as two projects on a machine depend on different versions of the same package, some projects will fail to run.
The solution is: virtual Environments.
A virtual environment is a replicated version of a real Python environment.
To install a virtual Environment command:
1. sudo pip install virtualenv #安装虚拟环境
2. sudo pip install virtualenvwrapper #安装虚拟环境扩展包
3. Edit the. bashrc file under the home directory and add the following two lines.
I. Export Workon_home= $HOME/.virtualenvs
II. source/usr/local/bin/virtualenvwrapper.sh
4. Use source. BASHRC to make it effective.
To Create a Virtual Environment command:
MKVIRTUALENV Virtual Environment name //default is Python2
To create a PYTHON3 virtual environment:
Mkvirtualenv-p Python3 Virtual Environment name
After entering the virtual environment: enter python to view the Python version
See how many virtual environments are on the machine:
Workon Space + two TAB key
Working in a virtual environment:
Workon Virtual Environment Name
The commands to exit the virtual environment are as follows:
Deactivate
To delete a variable environment:
RMVIRTUALENV Virtual Environment Name
Exit First: Deactivate
Again Delete: Rmvirtualenv py_djan3
commands for installing packages in a virtual environment:
Pip Install package name
Note: You cannot use the sudo pip install package name, this command installs the package to the real host environment rather than to the virtual environment.
To see which packages are installed in the virtual environment:
Method One: Pip list
Method Two: Pip freeze
Installing a Python virtual environment