欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python virtualenv cheatsheet

程序员文章站 2022-03-03 13:59:42
...

virtualenv cheatsheet

  • virtualenv cannot install arbitrary python version, but can install exist python version.

install

python3 -m pip install virtualenvwrapper

make sure python3 is the default python for system

sudo update-alternatives --config python

setup path

# <<< virtualenv setup <<<
# path for python package
export WORKON_HOME=$HOME/.virtualenvs
# path for project code
export PROJECT_HOME=$HOME/git
# default python for virtual python environment
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
source /usr/local/bin/virtualenvwrapper_lazy.sh
# >>> virtualenv setup >>>

usage

  • create environment
mkvirtualenv -a project_dir -i package_name -r requirements.txt --python /path/to/target/python
  • list environment workon, lsvirtualenv or showvirtualenv
  • activate environment workon envname
  • deactivate environment deactivate
  • dump environment pip freeze > requiremnts.txt
  • delete environment (deactivate first) rmvirtualenv