Python How to install virtualenv and Virtualenvwrapper

Source: Internet
Author: User
Tags install django pip install django virtual environment virtualenv
1. First introduction to pip common commands

PIP installation command: Pip install Package_name
PIP Upgrade command: Pip Install–ungrage package_name
Pip unload command: Pip uninstall package_name

Such as
Pip Install Django
Pip Install-u Django

2. Installation of virtualenv

Installation of virtualenv:

$ sudo pip install virtualenv

Or

$ sudo apt-get install python-virtualenv
If you are a Mac OS X system, you can install virtualenv with Easy_install:

$ sudo easy_install virtualenv
Check the version number of the virtualenv, or check to see if the system has Virtualenv installed:

$ virtualenv--version
To create a virtual environment with VIRTUALENV, the general virtual environment is named Venv:

$ virtualenv venv
Activate this virtual environment:

$ source Venv/bin/activate
If you are using a Microsoft Windows system, the activation command is:

$ venv\script\activate
The command that activates the virtual environment modifies the command-line prompt and joins the environment name:

(venv) $
When the work in the virtual environment is complete, if you want to go back to the global Python interpreter, you can enter deactivate at the command line prompt
Execute the following command to install flask in a virtual environment

(venv) $ pip Install flask
Verify that the flask is installed correctly:

(venv) $ python
>>> Import Flask
>>>

3. Installation of Virtualenvwrapper

Installation of Virtualenvwrapper:

$ sudo pip install Virtualenvwrapper
After the installation is complete, the Virtualwrapper shell script is generated in the following location.

/usr/local/bin/virtualenvwrapper.sh
When using Virtualenvwrapper, you need to configure the login shell initialization script to read the virtualenvwrapper.sh information into the current shell environment. Here, for example, the. BASHRC configuration file under the user root directory (i.e.,/home/[username]) can be modified as follows.
Modified. BASHRC:

if [-f/usr/local/bin/virtualenvwrapper.sh]; Then
Export Workon_home= $HOME/.virtualenvs
source/usr/local/bin/virtualenvwrapper.sh
Fi

Read again in. BASHRC:

$ source ~/.BASHRC
We can enter the command mkvirtualenv to see if it is available.

$ mkvirtualenv--help
Once set up, you can use the following command to manipulate the virtual environment:

Establish a virtual environment:

$ mkvirtualenv env
Confirm the virtual environment:

$ Ls-la $HOME/.virtualenvs
In the same place as the virtualenv, where the command to exit the virtual run environment is also deactivate, the command into the virtual run environment becomes Workon.
Exit the virtual Environment:

(venv) $ deactivate
Enter an existing environment or switch environment, assuming that there is a virtual environment named ENV:

$ Workon env
Browse Virtual environments:

$ workon
To delete a virtual environment:

$ rmvirtualenv env

4. Install PIP common Package in virtual environment under one click

The package or package== version number or package>= version number is written in the Requirements.txt file:

django==1.7.7
Django-debug-toolbar
Ply
Mysql-python
Uwsgi
Flup
Flask
Pillow
Markdown2

One-click installation command:

(venv) $ pip install-r requirements.txt
In the execution of the above one-click installation command process, the configuration Mysql-python when the system error, prompt:

Environmenterror:mysql_config not found
Google search Environmenterror:mysql_config not found, find the answer in StackOverflow

(venv) $ sudo apt-get install Libmysqlclient-dev
OK, Enjoy it!!!

Above this python installation virtualenv and Virtualenvwrapper method is small series to share all the content of everyone, hope to give you a reference, but also hope that we support topic.alibabacloud.com.

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.