ubuntu下Python虚拟环境配置
2018-01-15 09:53
363 查看
Python虚拟环境配置
VirtualEnv用于在一台机器上创建多个独立的python运行环境,VirtualEnvWrapper为前者提供了一些便利的命令行上的封装。1.安装virtualenv
pip install virtualenv #py2安装
1.1 virtualenv创建虚拟环境并进入使用
说明文档 You must provide a DEST_DIR Usage: virtualenv [OPTIONS] DEST_DIR Options: --version show program's version number and exit -h, --help show this help message and exit -v, --verbose Increase verbosity. -q, --quiet Decrease verbosity. -p PYTHON_EXE, --python=PYTHON_EXE The 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 (/usr/bin/python) --clear Clear out the non-root install and start from scratch. --no-site-packages DEPRECATED. Retained only for backward compatibility. Not having access to global site-packages is now the default behavior. --system-site-packages Give the virtual environment access to the global site-packages. --always-copy Always copy files rather than symlinking. --unzip-setuptools Unzip Setuptools when installing it. --relocatable Make an EXISTING virtualenv environment relocatable. This fixes up scripts and makes all .pth files relative. --no-setuptools Do not install setuptools in the new virtualenv. --no-pip Do not install pip in the new virtualenv. --no-wheel Do not install wheel in the new virtualenv. --extra-search-dir=DIR Directory to look for setuptools/pip distributions in. This option can be used multiple times. --download Download preinstalled packages from PyPI. --no-download, --never-download Do not download preinstalled packages from PyPI. --prompt=PROMPT Provides an alternative prompt prefix for this environment. --setuptools DEPRECATED. Retained only for backward compatibility. This option has no effect. --distribute DEPRECATED. Retained only for backward compatibility. This option has no effect.
安装需要版本的python
指定virtualenv中的python版本
virtualenv --no-site-packages --python=2.7 env<
a465
/li>
Note:
创建virtualenv虚拟环境之前,系统中必须要安装有对应版本的python,并且卸载之后当前虚拟环境就无效了。系统中可以同时存在python2和python3,通过环境变量中的系统变量path(不是用户变量)控制cmd或者系统中使用哪个版本的python,哪个版本的路径在前面就优先使用哪个版本。
–no-site-packages表示不包括系统全局的Python安装包,这样会更令环境更干净
–python=python2.7指定Python的版本未系统已经安装了的Python2.7
env是建立的虚拟环境名称
没有安装python2.7或者使用命令virtualenv –no-site-packages –python=python2.7 env会出现The executable python does notexist 错误
1.2进入虚拟环境并激活
$ . env/bin/activate
1.3退出虚拟环境
$ deactivate
1.4删除虚拟环境
$ rm -r venv
2.virtualenvwrapper
2.1 pip安装virtualenvwrapper
$ pip install virtualenvwrapper
2.2 初始化
将初始化文件写入用户环境变量$ vi .bashrc # 加入下面两行配置 source /usr/local/bin/virtualenvwrapper.sh # 虚拟环境指定路径,不指定默认使用~/.virtualenvs export WORKON_HOME="虚拟环境绝对路径"
创建:mkvirtualenv [虚拟环境名称]
删除:rmvirtualenv [虚拟环境名称]
进入:workon [虚拟环境名称]
退出:deactivate
所有的虚拟环境,都位于/home/.virtualenvs目录下
创建指定版的虚拟环境:
yangqian@ubuntu:~$ mkvirtualenv -p python3.5 test-3.5
相关文章推荐
- Ubuntu操作系统下Python虚拟环境Pipenv的安装和配置
- ubuntu下对Atom配置python的虚拟环境
- vscode在ubuntu下安装插件,同时配置python虚拟环境、ctrl+鼠标滚轮放大代码窗口设置
- 配置UBUNTU下bash、 python环境
- 【转】ubuntu下安装eclipse以及配置python编译环境
- python虚拟环境配置
- ubuntu环境下python虚拟环境的安装
- ubuntu下python虚拟环境安装、pycharm虚拟环境
- 【Ubuntu】Ubuntu16.04配置python环境(vim、ipython)
- ubuntu下配置python开发环境(Eclipese+Pydev)
- python编程中在ubuntu中安装虚拟环境及环境配置
- ubuntu14.04 配置python开发环境 eric4
- Ubuntu下VSCode的Python运行调试环境的配置
- ubuntu下配置python2.7.13神经网络环境
- Windows和Ubuntu下分别配置python开发环境
- 【Python配置】使用pyenv与virtualenv搭建单机多版本python多虚拟环境开发
- VirtualENV 配置python3虚拟环境
- Django开发环境配置(Ubuntu16.0.4 + python 2.7 + Django 1.8.7 +Sublime2)
- Ubuntu下配置舒服的Python开发环境
- python虚拟环境的配置