Install and configure virtualenv and virtualenvwrapper
- Install virtualenv and virtualenvwrapper
pip install virtualenv pip install virtualenvwrapper
- Create folder
mkdir $HOME/.virtualenvs
- Add in ~/.bashrc
The location of virtualenvwrapper.sh depends on the situation. It may be in theexport WORKON_HOME=$HOME/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source /usr/local/bin/virtualenvwrapper.sh
\usr\local\bin
middle or~/.local/bin
middle. - Activate the .bashrc file
source .bashrc
Note: If ERROR: virtualenvwrapper could not find virtualenv in your path appears , you can ~/.bashrc
add PATH=$PATH:~/.local/bin
or PATH=$PATH:/usr/local/bin
.
pip change source
Commonly used domestic sources
- Alibaba Cloud http://mirrors.aliyun.com/pypi/simple/
- University of Science and Technology of China https://pypi.mirrors.ustc.edu.cn/simple/
- Douban http://pypi.douban.com/simple/
- Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/
- University of Science and Technology of China http://pypi.mirrors.ustc.edu.cn/simple/
How to modify the source
- temporary use
- When using pip, add
-i
parameters to specify the pip source.
For example:pip install scrapy -i http://mirrors.aliyun.com/pypi/simple/
- When using pip, add
- Permanent modification
- create
~/.pip/pip.conf
- Add the following content
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
- Just save
- create
Common commands for virtualenv
- Create a virtual environment
- Based on python2
mkvirtualenv <env_name>
- Based on python3
mkvirtualenv -p python3 <env_name>
- Based on python2
- Exit the virtual environment
deactivate
- Delete virtual environment
rmvirtualenv <env_name>
- View all virtual environments
orworkon
lsvirtualenv
- Navigate to the directory of the currently active environment
cdvirtualenv
- Navigate to the site-packages directory of the currently active environment
cdsitepackages
- Display all contents in the site-packages directory
lssitepackages
- View the installed packages in the current environment
orpip list
pip freeze
- Check which packages in the current environment need to be updated
orpip list --outdated
pip list -o
- Upgrade the current environment package
orpip install -U package_name
pip install --upgrade package_name
- Install the package online for the current environment (you can specify the package version by using "==", ">=", "<=", ">", "<")
orpip install package_name
pip install -r package_names.txt
- Install the downloaded local installation package for the current environment
pip install <目录>/<文件名>
- Uninstall the package of the current environment
orpip uninstall package_name
pip uninstall -r package_names.txt
- View the package directory
pip show -f package_name
- Search package
pip search keywords
- Download the package without installing
orpip install package_name -d <目录>
pip install -r package_names.txt -d <目录>
- Package all packages of the current virtual environment
pip freeze > package_names.txt