Ubuntu virtualenv 创建 python2 虚拟环境 激活 退出

mac2022-06-30  108

首先默认安装了virtualenv 创建python2虚拟环境

your-name@node-name:~/virtual_env$ virtualenv -p /usr/bin/python2 py2env

接着会输出

Running virtualenv with interpreter /usr/bin/python2 New python executable in /home/your_name/virtual_env/py2env/bin/python2 Also creating executable in /home/your_name/virtual_env/py2env/bin/python Installing setuptools, pkg_resources, pip, wheel...done.

这时候就创建出了一个python2的环境,然后测试下是否是我们想要的环境 激活环境

source ~/virtual_env/py2env/bin/activate

然后 shell 终端会有这样的前缀

(py3env) your-name@node-name:~/virtual_env$

这表明你已经进入了这个python2的虚拟环境 然后查看是否是python2

(py3env) your-name@node-name:~/virtual_env$ python

输出

Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>

可以看出python环境是2.7.12 下面介绍退出虚拟环境 在shell终端输入

(py2env) your-name@node-name:~/virtual_env$ deactivate

然后终端显示

your-name@node-name:~/virtual_env$

转载于:https://www.cnblogs.com/vercont/p/10210221.html

最新回复(0)