python运行环境管理工具virtualenv

如果A项目依赖 django 1.9,B项目依赖django2.0,则会出现依赖冲突。
怎么解决呢?就要用到本文所提到的工具 virtualenv 。
本文是在
windows进行的操作,其它系统操作过程可能略有不同。
virtualenv 的安装和基本使用方法
# 安装pip install virtualenv
# 检查是否安装成功
virtualenv --version
创建新项目和执行环境
# 创建新项目mkdir demo
cd demo
# 创建独立的运行环境
virtualenv env
# 激活环境
./env/Scripts/activate
# 解除环境(恢复到默认环境)
./env/Scripts/deactivate
在linux下,激活环境的命令式
source bin/activate,取消激活方法是deactivate。
--system-site-packages 参数
使用 virtualenv --system-site-packages env 参数可以继承全局环境的依赖库,...python3.7/site-packages 中的依赖资源会被复制到新的环境中。
--extra-search-dir 参数
使用 --extra-search-dir 可以指定本地其它的环境版本,假如本地同时存在 python2.7,则可按如下方式创建基于python2.7的新环境:
virtualenv --extra-search-dir=D:/Program Files/Python27 env其它参数
--versionshow program’s version number and exit-h, --helpshow this help message and exit-v, --verboseIncrease verbosity.-q, --quietDecrease verbosity.-p PYTHON_EXE, --python=PYTHON_EXEThe Python interpreter to use, e.g., –python=python2.5 will use the python2.5 interpreter to create the new environment. The default is the interpreter that virtualenv was installed with (like /usr/bin/python)--clearClear out the non-root install and start from scratch.--system-site-packagesGive the virtual environment access to the global site-packages.--always-copyAlways copy files rather than symlinking.--relocatableMake an EXISTING virtualenv environment relocatable. This fixes up scripts and makes all .pth files relative.--unzip-setuptoolsUnzip Setuptools when installing it.--no-setuptoolsDo not install setuptools in the new virtualenv.--no-pipDo not install pip in the new virtualenv.--no-wheelDo not install wheel in the new virtualenv.--extra-search-dir=DIRDirectory to look for setuptools/pip distributions in. This option can be specified multiple times.--prompt=PROMPTProvides an alternative prompt prefix for this environment.--downloadDownload preinstalled packages from PyPI.--no-downloadDo not download preinstalled packages from PyPI.--no-site-packagesDEPRECATED. Retained only for backward compatibility. Not having access to global site-packages is now the default behavior.--distribute--setuptoolsLegacy; now have no effect. Before version 1.10 these could be used to choose whether to install Distribute or Setuptools into the created virtualenv. Distribute has now been merged into Setuptools, and the latter is always installed.
以上是 python运行环境管理工具virtualenv 的全部内容, 来源链接: utcz.com/z/513776.html

