# add the below line into ~/.bash_profile or ~/.zshrc, to auto-active pyenv ifwhich pyenv > /dev/null; theneval"$(pyenv init -)"; fi
# Create a root path for virtualenvs we will created by virtualenv and virtualenvwrapper. mkdir ~/.virtualenvs
# Set default path for virutalenvs in .zshrc or .bashrc. export WORKON_HOME=~/.virtualenvs
# Enable virutalenvwrapper in .zshrc or .bashrc. ## As I am using python 3.7 created by pyenv, my virtualenvwrapper.sh script is located in */Users/daniel/.pyenv/versions/3.7.0/bin/virtualenvwrapper.sh*. source /usr/local/bin/virtualenvwrapper.sh
# Enable virutalwrapper right now! source ~/.zshrc
Some useful pyenv commands are: commands List all available pyenv commands local Set or show the local application-specific Python version global Set or show the global Python version shell Set or show the shell-specific Python version install Install a Python version using python-build uninstall Uninstall a specific Python version rehash Rehash pyenv shims (run this after installing executables) version Show the current Python version and its origin versions List all Python versions available to pyenv which Display the full path to an executable whence List all Python versions that contain the given executable
virtualenv + virtualenvwrapper
场景:同时有两个项目 A 和 B,都需要使用 request 包,但由于外部依赖或兼容老系统等原因,A 和 B 需要使用的 request 包的版本有差异。此时,可以创建两个不同的虚拟环境,在各自的环境下分别安装对应版本的 request 包。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Create a virtualenv named py3dev. mkvirtualenv py3dev
# Create a virtualenv named py3dev ignore the system site packages. mkvirtualenv --no-site-packages py3dev