The Installation Process of the python virtual environment in ubuntu environment, ubuntupython

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

The Installation Process of the python virtual environment in ubuntu environment, ubuntupython

1. Virtual Environment Construction

How to install a module in development:

Pip install Module name

Previously, our installation modules were directly installed in the physical environment. This installation method overwrites the previous one. What if multiple projects developed on one machine use modules of different versions? How can we do this without affecting the version! You need to use a virtual environment. Each virtual environment is isolated from each other. Installing and uninstalling modules in a virtual environment is not affected!

1. python Virtual Environment Installation

sudo apt-get install python-virtualenvsudo easy_install virtualenvwrapper

After the tool is installed, the mkvirtualenv command cannot be found. You need to execute the following environment variable settings.

1. Create a directory to store the Virtual Environment

mkdir $HOME/.virtualenvs

2. In ~ /. Add rows to 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. Exit the Virtual Environment

Deactivate [Virtual Environment name]

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

Rmvirtualenv [Virtual Environment name]

6. Create python 2 for development

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

7. Create python 3 for development

mkvirtualenv -p /usr/bin/python3 py3

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

1. You do not need to add sudo to the installation module in the virtual environment. If you add sudo, it will be installed in the real environment, and you do not need to specify the pip version. You can directly use pip for installation.

workon py3 pip install django==1.8.2

2. Check the packages installed in the virtual environment.

pip freeze list

3. After the project is developed, you need to export and install the packages used in the development environment to the production environment.

pip freeze list > package.txt

4.install the package.txt file of the development environment to the production environment

Summary

The above is the installation process of the python Virtual Environment In ubuntu. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in time!

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.