virtualenv管理py环境linux版
因为服务器上已经安装了python3,所以直接安装virtualenv即可
pip3 install virtualenv -i https://mirrors.aliyun.com/pypi/simple/
查找此包安装在什么地方
[root@172 edu-manage]#
[root@172 edu-manage]# virtualenv -help
bash: virtualenv: command not found
[root@172 edu-manage]# whereis virtualenv
virtualenv: /opt/python37/bin/virtualenv
[root@172 edu-manage]#
建立软链,方便使用
[root@172 bin]# ln -s /opt/python37/bin/virtualenv /usr/bin/virtualenv
创建虚拟环境
$ virtualenv [OPTIONS] [虚拟环境名称]
#顺序都可以
virtualenv -p /usr/bin/python3.6 ENV
virtualenv -p /usr/bin/python3.6 ENV
virtualenv ENV --python=python3.6
virtualenv --python=python3.6 ENV
[root@172 ~]# whereis python3
python3: /usr/bin/python3 /opt/python37/bin/python3.7m /opt/python37/bin/python3.7 /opt/python37/bin/python3.7m-config /opt/python37/bin/python3 /opt/python37/bin/python3.7-config
[root@172 ~]#
[root@172 ~]# virtualenv -p /usr/bin/python3 export_data
created virtual environment CPython3.7.5.final.0-64 in 391ms
creator CPython3Posix(dest=/root/export_data, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==21.3.1, setuptools==58.3.0, wheel==0.37.0
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
[root@172 ~]#
[root@172 ~]#
创建的虚拟环境是不会把原始解释器所在的环境下的包带过来的
进入虚拟环境&退出
[root@172 ~]# cd export_data/
[root@172 export_data]# ls
bin lib pyvenv.cfg
[root@172 export_data]#
[root@172 export_data]#
[root@172 export_data]# cd bin/
[root@172 bin]# ls
activate activate.nu deactivate.nu pip-3.7 python3 wheel3
activate.csh activate.ps1 pip pip3.7 python3.7 wheel-3.7
activate.fish activate_this.py pip3 python wheel wheel3.7
[root@172 bin]#
# 进入环境
[root@172 bin]# source activate
(export_data) [root@172 bin]#
(export_data) [root@172 bin]#
# 退出环境
(export_data) [root@172 bin]# deactivate
[root@172 bin]#