python method for installing virtualenv and virtualenvwrapper

  • 2020-05-24 05:42:51
  • OfStack

1. Start with the common pip commands

pip installation command: pip install package_name
pip upgrade command: pip install, ungrage package_name
pip uninstall 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 it is Mac OS X system, virtualenv can be installed with easy_install:

$ sudo easy_install virtualenv
Check the version number of virtualenv, or check if the system is installed with virtualenv:

$ virtualenv --version
Create a virtual environment with virtualenv. The general virtual environment is named venv:

$ virtualenv venv
Activate the virtual environment:

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

$ venv\Script\activate
The command to activate the virtual environment changes the command line prompt to add the environment name:

(venv) $
When the work in the virtual environment is complete, if you want to go back to the global Python interpreter, type deactivate at the command line prompt
To install Flask in a virtual environment, follow these commands

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

(venv) $ python
> > > import flask
> > >

3. Installation of virtualenvwrapper

Installation of virtualenvwrapper:

$ sudo pip install virtualenvwrapper
When the installation is complete, the shell script for virtualwrapper 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. For the example of base, the.bashrc configuration file in 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 in again.bashrc:

$ source ~/.bashrc
We can enter the command mkvirtualenv and see if it is available under 1.

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

Create a virtual environment:

$ mkvirtualenv env
Confirm virtual environment:

$ ls -la $HOME/.virtualenvs
Where, the command to exit the virtual running environment is also deactivate, and the command to enter the virtual running environment becomes workon.
Exit virtual environment:

(venv) $ deactivate
Enter the existing environment or switch the environment. Suppose there is a virtual environment named env:

$ workon env
Browse virtual environment:

$ workon
Delete virtual environment:

$ rmvirtualenv env

4. Install pip commonly used package in virtual environment with 1 key

package or package== version number or package > = version number:

Django==1.7.7
django-debug-toolbar
ply
MySQL-python
uwsgi
flup
Flask
Pillow
markdown2

1 key installation command:

(venv) $ pip install -r requirements.txt
During the execution of the 1 key installation command above, when configuring MySQL-Python, the system will report an error, indicating:

EnvironmentError: mysql_config not found
google search EnvironmentError: mysql_config not found, find the answer at stackoverflow

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


Related articles: