How to install virtualenv and virtualenvwrapper in python, virtualenvwrapper

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

How to install virtualenv and virtualenvwrapper in python, virtualenvwrapper

1. First introduce pip Common commands

Pip installation command: pip install package_name
Pip upgrade command: pip install-ungrage package_name
Pip uninstall command: pip uninstall package_name

For example
Pip install django
Pip install-U django

2. virtualenv Installation

Virtualenv installation:

$ Sudo pip install virtualenv

Or

$ Sudo apt-get install python-virtualenv
For Mac OS X, you can use easy_install to install virtualenv:

$ Sudo easy_install virtualenv
Check the virtualenv version number or whether the system has virtualenv installed:

$ Virtualenv -- version
Use virtualenv to create a virtual environment. Generally, the virtual environment is named venv:

$ Virtualenv venv
Activate this virtual environment:

$ Source venv/bin/activate
If you use Microsoft windows, the activation command is:

$ Venv \ Script \ activate
The command to activate the virtual environment modifies the command line prompt and adds the environment name:

(Venv) $
After the work in the virtual environment is complete, if you want to return to the global Python interpreter, you can enter deactivate at the command line prompt.
Run the following command to install Flask in a virtual environment:

(Venv) $ pip install flask
Verify that Flask is correctly installed:

(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 at the following position.

/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, we use base as an example to modify the. bashrc configuration file in the root directory of the user (that is,/home/[username]) as follows.
Modify. bashrc:

If [-f/usr/local/bin/virtualenvwrapper. sh]; then
Export WORKON_HOME = $ HOME/. virtualenvs
Source/usr/local/bin/virtualenvwrapper. sh
Fi

Read again. bashrc:

$ Source ~ /. Bashrc
Run the mkvirtualenv command to check whether it is available.

$ Mkvirtualenv -- help
After setting, you can use the following command to operate the virtual environment:

Create a virtual environment:

$ Mkvirtualenv env
Confirm the virtual environment:

$ Ls-la $ HOME/. virtualenvs
In the same and different ways as virtualenv, the command to exit the virtual runtime environment is also deactivate, and the command to enter the virtual runtime environment becomes workon.
Exit the virtual environment:

(Venv) $ deactivate
Enter an existing environment or switch the environment. Assume that the virtual environment name is env:

$ Workon env
Browse the virtual environment:

$ Workon
Delete a virtual environment:

$ Rmvirtualenv env

4. one-click installation of pip commonly used package in a Virtual Environment

In the requirements.txt file, write package or package ==version or package >=version:

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
During the execution of the one-click installation command above, the system reports an error when configuring MySQL-Python:

EnvironmentError: mysql_config not found
Google search EnvironmentError: mysql_config not found and find the answer in stackoverflow

(Venv) $ sudo apt-get install libmysqlclient-dev
OK, Enjoy it !!!

The method for installing virtualenv and virtualenvwrapper in python above is all the content that I have shared with you. I hope you can give me a reference and support the help house.

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.