Python installs virtualenv and Virtualenvwrapper

Source: Internet
Author: User

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.shfi

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 Requirements.txt file is written in package or package==版本号 or package>=版本号 :

Django==1.7.7django-debug-toolbarplyMySQL-pythonuwsgiflupFlaskPillowmarkdown2

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 answers in StackOverflow

(venv) $ sudo apt-get install libmysqlclient-dev

OK, Enjoy it!!!

Python installs virtualenv and Virtualenvwrapper

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.