Installation of Python virtual environment in Ubuntu environment

Source: Internet
Author: User
Tags install django pip install django virtual environment

I. Virtual Environment CONSTRUCTION

Methods for installing modules in development:

Pip Install module name

Before we installed the modules are directly in the physical environment installation, this installation method, the subsequent installation will overwrite the previous installation. What if a single machine developed multiple projects using different versions of the module? What to do to not be affected by the version! Then need to use the virtual environment, each virtual environment isolated from each other, in a virtual environment loading module other not affected!

1. Python Virtual Environment installation
sudo apt-get install python-virtualenvsudo easy_install Virtualenvwrapper

The mkvirtualenv command is not found when the above tool is installed, and the following environment variable settings are required.

1. Create a directory to store the virtual environment

$HOME/.virtualenvs

2. Add lines in ~/.BASHRC:

Export Workon_home=$HOME/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh

3. Run:

Source ~/.BASHRC

3. Create a Python virtual environment

mkvirtualenv [Virtual Environment name]workon [virtual environment name]

4. Exiting the virtual environment

Deactivate [virtual Environment name]

5. Delete (use caution) first 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. Installing the module in a virtual environment does not require sudo, if add sudo will be installed in the real environment, do not need to specify the version of PIP, directly using PIP installation can.

Workon py3 pip Install django= =1.8. 2

2. See which packages are installed in the virtual environment

PIP Freeze List

3. Project development completed, need to be on-line, the development environment to use the package, export installation into the production environment.

> package.txt

4. Install the file Package.txt of the package exported by the development environment into the production environment

Pip Install-r package.txt

Installation of Python virtual environment in Ubuntu environment

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.