ubuntu environment python virtual environment installation process

  • 2020-06-23 00:59:58
  • OfStack

1. Virtual environment construction

Methods for installing modules in development:

pip install 模块名称

Before, we installed modules directly under the physical environment. In this installation method, those installed in the second installation will cover those installed in the first installation. What if there are multiple projects on one machine that use different versions of modules? How to do not be affected by the version! Then virtual environment is needed, each virtual environment is isolated from each other, install and uninstall modules in one virtual environment and other are not affected!

1. python virtual environment installation

sudo apt-get install python-virtualenv
sudo easy_install virtualenvwrapper

The mkvirtualenv command cannot be found after the above tools are installed. The following environment variable Settings need to be performed.

1. Create a directory to hold your virtual environment

mkdir $HOME/.virtualenvs

2. Add lines to ~/.bashrc:

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

3. Run:

source ~/.bashrc

3. Create python virtual environment

mkvirtualenv [ Virtual environment name ]
workon [ Virtual environment name ]

Exit the virtual environment

deactivate [ Virtual environment name ]

5. Delete (use with caution) and return to the virtual environment

rmvirtualenv [ Virtual environment name ]

6. Create python 2 version development

mkvirtualenv -p /usr/bin/python2.7 py2

7. Create python 3 version development

mkvirtualenv -p /usr/bin/python3 py3

2. Install the module with the specified version number in the virtual environment

1. sudo is not needed to install modules in the virtual environment. If sudo is added, it will be installed in the real environment.

workon py3 
pip install django==1.8.2

2. See which packages are installed in the virtual environment

mkdir $HOME/.virtualenvs

3. Export and install the package used in the development environment to the production environment when the project is completed and needs to go online.

mkdir $HOME/.virtualenvs

4. Install package.txt from the package exported from the development environment into the production environment


Above is the site to introduce ubuntu environment python virtual environment installation process, I hope to help you, if you have any questions welcome to leave a message, this site will reply you in time!

Related articles: