2017-09-07 33 views
0

我下面就的virtualenv本指南Python和遇到了一个小问题:如何检查virtualenvwrapper已经安装VIRTUALENVWRAPPER_PYTHON =的/ usr/bin中/蟒蛇等

Sahands-MBP:empty sahandzarrinkoub$ source /usr/local/bin/virtualenvwrapper.sh 
/usr/bin/python: No module named virtualenvwrapper 
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/python and that PATH is 
set properly. 

打印输出是相当很有帮助。它说我需要检查virtualenvwrapper已安装为VIRTUALENVWRAPPER_PYTHON=/usr/bin/python,并且PATH已正确设置。唯一的问题是,我不知道这些是什么意思。所以我的问题是:

  1. 这是什么意思,virtualenvwrapper已被“安装”VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
  2. 什么是在这种情况下正确设置PATH

回答

3

不完全确定你需要什么,但也许这会有所帮助。它有点冗长,但希望能回答你的问题:

这里有很多事情要做。

首先,/usr/local/bin/virtualenvwrapper.sh是一个shell脚本。如果你读了剧本,你会看到下面的代码:

# Locate the global Python where virtualenvwrapper is installed. 
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] 
then 
    VIRTUALENVWRAPPER_PYTHON="$(command \which python)" 
fi 

这意味着该virtualenvwrapper.sh脚本使用名为VIRTUALENVWRAPPER_PYTHON一个环境变量来确定Python安装。这很重要,因为:

其次,可以在系统上安装多个版本的python。 (我目前有3:2.7,3.5和3.6)。并且无论如何与Linux系统,

/usr/bin/python 

符号链接到其中一个版本。这是它的外观我的系统在Linux系统上:

lenovo:davidj ~ > ls -l /usr/bin/python 
lrwxrwxrwx 1 root root 24 Apr 28 23:36 /usr/bin/python -> 
/etc/alternatives/python 
lenovo:davidj ~ > ls -l /etc/alternatives/python 
lrwxrwxrwx 1 root root 18 Aug 31 14:56 /etc/alternatives/python -> 
/usr/bin/python3.6 

因此,符号链接的链之后,当我运行

/usr/bin/python 

我运行3.6版本。我可以随意更改这些链接,以指向版本2.7,3.5或我可能安装的任何其他版本。

这意味着什么:除非您将VIRTUALENVWRAPPER_PYTHON设置为特定的python安装,否则/usr/local/bin/virtualenvwrapper.sh将默认为/ usr/bin/python以确定默认的python版本运行。

对我来说,在我的.bashrc文件我有

export VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3.6' 

这意味着virtualenvwrapper将使用Python 3.6,因为我告诉它使用特定版本。

在你的情况下,脚本失败,因为virtualenvwrapper没有安装该版本的/ usr/bin/python指向的python版本。要确定你的python版本,只需运行:

python -V 

然后为该版本安装virtualenvwrapper。

我希望这会有所帮助。

+1

非常感谢。我通过将我的VIRTUALENVWRAPPER_PYTHON变量指向安装了virtualenvwrapper的python版本(python3)来解决我的问题。所以,我将这一行添加到我的.bash_profile中: 'export VIRTUALENVWRAPPER_PYTHON =/usr/local/bin/python3' – Sahand

0

你只需要添加此行到〜/ .zshrc或.bash_profile文件:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2