学习过程中安装virtualenvwrapper和virtualenv产生了如下问题,记录一下解决方案
根据百度上面的博客安装这两个模块包,需要修改配置文件,修改好后,在source命令后
# Python Virtualenv Settings
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
# 指定virtualenv的路径
export VIRTUALENVWRAPPER_VIRTUALENV=~/.local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
source ~/.bashrc
出现了如下的错误:
-bash: /usr/bin/python3: 没有那个文件或目录
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is
set properly
?这是由于virtualenvwrapper_python的路径配置的不对,个人的系统文件路径不一样,都根据网上的修改,由于不太懂,很容易出问题,我就是其中一个
????????由于我的Python3路径通过软连接现在的准确路径是/usr/bin/python,不是网上大家的usr/bin/python3,这个可以通过which python这个命令查看个人的路径
? ? ? ? 修改好这个问题后,再source ~/.bashrc配置文件使其生效,发现不报错了,进入下一步,通过mkvirtualenv创建虚拟环境,发现又报错了
[yin@localhost myproject]$ mkvirtualenv temp
which: no virtualenv in (/usr/local/python/python3/lib/python3.7/site-packages)
ERROR: virtualenvwrapper could not find /usr/local/python/python3/lib/python3.7/site-packages/virtualenv in your path
?这里的报错和上面问题一样,是文件的路径不对,这个是由于virtualenvwrapper_virtualenv这里的配置不对,可以通过如下命令查到自己的路径
[yin@localhost ~]$ sudo find / -name virtualenv
/usr/local/python/python3/bin/virtualenv
/usr/local/python/python3/lib/python3.7/site-packages/virtualenv
/home/yin/.local/share/virtualenv
[yin@localhost ~]$ sudo find / -name virtualenvwrapper
/usr/local/python/python3/lib/python3.7/site-packages/virtualenvwrapper
?然后根据实际的地址将配置文件修改完成如下
# Python Virtualenv Settings
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
# 指定virtualenv的路径
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python/python3/bin/virtualenv
source /usr/local/python/python3/bin/virtualenvwrapper.sh
?至此,安装顺利结束
|