Python虚拟环境
-
确认python解释器的路径
[root@i-h0xe1oiq ~]# which python3.9 /usr/local/bin/python3.9
-
安装python虚拟运行环境
pip3.9 install virtualenv pip3.9 install virtualenvwrapper
-
创建目录来存放虚拟环境
mkdir $HOME/.virtualenvs
-
在~/.bashrc中配置环境变量
export WORKON_HOME=$HOME/.virtualenvs VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.9 source /usr/local/bin/virtualenvwrapper.sh
-
加载环境变量
source ~/.bashrc
-
创建虚拟环境
[root@i-h0xe1oiq data]# mkvirtualenv -p /usr/local/bin/python3.9 env39 created virtual environment CPython3.9.7.final.0-64 in 1132ms creator CPython3Posix(dest=/root/.virtualenvs/env39, 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.2.4, setuptools==58.1.0, wheel==0.37.0 activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator virtualenvwrapper.user_scripts creating /root/.virtualenvs/env39/bin/predeactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/env39/bin/postdeactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/env39/bin/preactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/env39/bin/postactivate virtualenvwrapper.user_scripts creating /root/.virtualenvs/env39/bin/get_env_details (env39) [root@i-h0xe1oiq data]# #可以看到创建之后直接进入到了虚拟环境中
-
退出虚拟环境
(env39) [root@i-h0xe1oiq data]# deactivate [root@i-h0xe1oiq data]#
-
查看虚拟环境
[root@i-h0xe1oiq data]# lsvirtualenv env39 =====
-
进入虚拟环境
[root@i-h0xe1oiq data]# workon env39 (env39) [root@i-h0xe1oiq data]#
-
删除虚拟环境
[root@i-h0xe1oiq data]# rmvirtualenv env39 Removing env39...