python-centos7下安装python3虚拟环境

python-centos7下安装python3虚拟环境,第1张

概述1.创建python的虚拟环境[root@python~]#mkdir-p/virtualenvs安装虚拟环境virtualenv[root@python~]#pip3installvirtualenv-ihttps://pypi.tuna.tsinghua.edu.cn/simple/安装虚拟环境扩展包[root@pythonvirtualenvs]#pip3installvirtualenvwra 1.创建python的虚拟环境

[root@python ~]# mkdir -p /virtualenvs

安装虚拟环境virtualenv

[root@python ~]#   pip3 install virtualenv -i https://pypi.tuna.tsinghua.edu.cn/simple/     

安装虚拟环境扩展包

[root@python   virtualenvs]# pip3 install virtualenvwrapper    -i https://pypi.tuna.tsinghua.edu.cn/simple/      
2. 修改用户家目录下的配置文件.bashrc,添加如下内容

修改配置文件

#查找一下安装的虚拟环境扩展包文件[root@python virtualenvs]# find / -name virtualenvwrapper.sh/usr/local/python3/bin/virtualenvwrapper.sh#配置环境变量[root@python virtualenvs]# vim /etc/profile[root@python virtualenvs]# tail -n 4 /etc/profileexport WORKON_HOME=/virtualenvsexport VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source /usr/local/python3/bin/virtualenvwrapper.sh

执行环境文件,重新加载文件,使配置配置文件生效

[root@python virtualenvs]# source /etc/profilevirtualenvwrapper.user_scripts creating /virtualenvs/premkprojectvirtualenvwrapper.user_scripts creating /virtualenvs/postmkprojectvirtualenvwrapper.user_scripts creating /virtualenvs/initializevirtualenvwrapper.user_scripts creating /virtualenvs/premkvirtualenvvirtualenvwrapper.user_scripts creating /virtualenvs/postmkvirtualenvvirtualenvwrapper.user_scripts creating /virtualenvs/prermvirtualenvvirtualenvwrapper.user_scripts creating /virtualenvs/postrmvirtualenvvirtualenvwrapper.user_scripts creating /virtualenvs/predeactivatevirtualenvwrapper.user_scripts creating /virtualenvs/postdeactivatevirtualenvwrapper.user_scripts creating /virtualenvs/preactivatevirtualenvwrapper.user_scripts creating /virtualenvs/postactivatevirtualenvwrapper.user_scripts creating /virtualenvs/get_env_details
3. 创建python3虚拟环境的命令如下

创建虚拟环境,mkvirtualenv “虚拟环境名称”

创建命令:

mkvirtualenv 环境名称   

执行创建虚拟环境命令

[root@python virtualenvs]# mkvirtualenv  python_3.8_basewhich: no virtualenv in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)ERROR: virtualenvwrapper Could not find virtualenv in your path#提示报错我们需要链接一下virtualenv[root@python virtualenvs]# ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv

重新执行创建虚拟环境命令

root@python virtualenvs]# mkvirtualenv  python_3.8_basecreated virtual environment Cpython3.7.4.final.0-64 in 969ms  creator Cpython3Posix(dest=/virtualenvs/python_3.8_base, clear=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==20.1.1, setuptools==49.2.0, wheel==0.34.2  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivatorvirtualenvwrapper.user_scripts creating /virtualenvs/python_3.8_base/bin/predeactivatevirtualenvwrapper.user_scripts creating /virtualenvs/python_3.8_base/bin/postdeactivatevirtualenvwrapper.user_scripts creating /virtualenvs/python_3.8_base/bin/preactivatevirtualenvwrapper.user_scripts creating /virtualenvs/python_3.8_base/bin/postactivatevirtualenvwrapper.user_scripts creating /virtualenvs/python_3.8_base/bin/get_env_details

切换虚拟环境:使用"workon 虚拟环境名称" 切换虚拟环境

命令示例:

(Flask_cmdb)   [root@python virtualenvs]# workon python_3.8_base   (python_3.8_base)  [root@python virtualenvs]# 

退出虚拟环境:使用 “deactivate”命令退出虚拟环境

命令示例

(python_3.8_base)   [root@python virtualenvs]# deactivate   

删除虚拟环境:使用“rmvirtualenv 虚拟环境名称”

命令示例:

[root@python   virtualenvs]# rmvirtualenv python_3.8_base   Removing   python_3.8_base...  

改为阿里云的pip库

[root@python virtualenvs]# mkdir -p ~/.pip[root@python virtualenvs]# vim ~/.pip/pip.conf[root@python virtualenvs]# cat ~/.pip/pip.conf [global]index-url = http://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com
总结

以上是内存溢出为你收集整理的python-centos7下安装python3虚拟环境全部内容,希望文章能够帮你解决python-centos7下安装python3虚拟环境所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1186956.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存