CentOS7系統安裝虛擬環境,安裝及相關報錯問題解決方案、配置、問題解決、常見相關命令

python-Mr.Lin發表於2020-10-14

第一步:安裝virtualenvwrapper

命令:pip3 install -i https://pypi.douban.com/simple virtualenvwrapper

有些小夥伴安裝virtualenvwrapper時可能會出現報錯: 

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lna_rq3y/virtualenvwrapper/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lna_rq3y/virtualenvwrapper/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ldlw2k__
         cwd: /tmp/pip-install-lna_rq3y/virtualenvwrapper/
    Complete output (34 lines):
    WARNING: The wheel package is not available.
    WARNING: The repository located at mirrors.cloud.aliyuncs.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.cloud.aliyuncs.com'.
    ERROR: Could not find a version that satisfies the requirement pbr (from versions: none)
    ERROR: No matching distribution found for pbr
    Traceback (most recent call last):
      File "/usr/local/lib/python3.6/site-packages/setuptools/installer.py", line 128, in fetch_build_egg
        subprocess.check_call(cmd)
      File "/usr/lib64/python3.6/subprocess.py", line 311, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpjjhoqpjz', '--quiet', '--index-url', 'http://mirrors.cloud.aliyuncs.com/pypi/simple/', 'pbr']' returned non-zero exit status 1.
    
    During handling of the above exception, another exception occurred:
省略......

解決方案及步驟:

1. 升級pip: sudo pip install --upgrade pip

2. 升級setuptools: sudo pip install --upgrade setuptools

3. 安裝pbr擴充套件包:

sudo pip install pbr -i https://pypi.tuna.tsinghua.edu.cn/simple

sudo pip install --no-deps stevedore -i https://pypi.tuna.tsinghua.edu.cn/simple

sudo pip install virtualenvwrapper -i https://pypi.tuna.tsinghua.edu.cn/simple

OK,以上步驟完成後,再次執行安裝虛擬環境命令。


第二步:在.bashrc配置虛擬環境

.bashrc位置:一般在根目錄下,操作 ls -a 命令可以檢視到 ,如果沒有找到請操作:find / -name .bashrc

執行:sudo vim vim ~/.bashrc

進入編輯模式,將以下內容複製 fi 後面

# 虛擬環境配置
export WORKON_HOME=~/Envs   #設定virtualenv的統一管理目錄
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'   #新增virtualenvwrapper的引數,生成乾淨隔絕的環境
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3     #指定成自己的python直譯器
source /usr/local/bin/virtualenvwrapper.sh  # 指定成自己的執行virtualenvwrapper安裝指令碼

然後重啟系統,就可以正常操作了


第三步:常用命令

mkvirtualenv django_go 建立虛擬環境

mkvirtualenv 名字:建立虛擬環境

workon 名字:切換虛擬環境

rmvirtualenv 名字:刪除虛擬環境

lsvirtualenv:列舉所有虛擬環境

deactivate:退出虛擬環境


謝謝大家支援!如能有用,請記得收藏哦!!!

相關文章