从github使用-e选项将pip安装到virtualenv中使用-e选项无法将包添加到python路径

问题描述:

我试图从我的github中以“可编辑”(-e)模式安装软件包,以便能够轻松地在存储库上工作,同时使用它。从github使用-e选项将pip安装到virtualenv中使用-e选项无法将包添加到python路径

然而,它造成的问题,因为它安装后它不可用在python路径。

随着创建并激活一个清新,洁净的virtualenv“发行人”,我运行以下命令:

pip install -e git+https://github.com/roberts81/easy-thumbnails.git#egg=easy_thumbnails 
Obtaining easy-thumbnails from git+https://github.com/roberts81/easy-thumbnails.git#egg=easy_thumbnails 
    Cloning https://github.com/roberts81/easy-thumbnails.git to /Users/ben/Envs/publisher/src/easy-thumbnails 
    Running setup.py egg_info for package easy-thumbnails 

    no previously-included directories found matching 'docs/_build' 
Installing collected packages: easy-thumbnails 
    Running setup.py develop for easy-thumbnails 

    no previously-included directories found matching 'docs/_build' 
    Creating /Users/ben/Envs/publisher/lib/python2.7/site-packages/easy-thumbnails.egg-link (link to .) 
    Adding easy-thumbnails 1.2 to easy-install.pth file 

    Installed /Users/ben/Envs/publisher/src/easy-thumbnails 
Successfully installed easy-thumbnails 
Cleaning up... 

然后,如果我运行python(仍然在我的virtualenv),并尝试从包中导入任何东西,它失败。

Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import easy_thumbnails 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named easy_thumbnails 
>>> 

如果我安装它没有-e选项,一切工作丹迪。我可以用其他回购的方式获得相同的效果(即,它们不在安装后的python路径中),例如, pip install -e git+http://github.com/django/[email protected]/1.5.x#egg=django。那么是什么给了?

我注意到的一件事是,它似乎并没有真正更新easy-install.pth文件,即使它说它是...这里有些奇怪的事情。

但是,如果我运行它(PIP安装...命令)与sudo,它的工作原理!另外,我可以在全球范围内安装软件包(virtualenv之外,当然还有sudo)并且工作正常。

版本:

PIP == 1.2.1 的virtualenv == 1.8.4 virtualenvwrapper == 3.6 蟒蛇== 2.7.2 的Mac OSX 10.8.2

+0

看着它,它说“添加easy-thumbnails 1.2到easy-install.pth文件”......但我没有在.pth文件中看到任何引用易于缩略图的东西。究竟是怎么回事? (我发誓这工作得很好) – 2013-02-24 03:46:30

+0

试图卸载并重新安装pip,virtualenv,virtualenvwrapper,没有运气。 – 2013-02-24 03:57:30

我有一个类似的问题,并通过删除我的virtualenv,重新创建它,激活它,然后(在做其他事情之前)更新环境中的pip和setuptools来解决它。首先打开一个新的终端窗口(以确保虚拟env未被激活)并导航到您的virtualenv所在的目录。然后做:

rm -rf env 
virtualenv env 
. env/bin/activate 
pip install -U pip setuptools 

这我能够安装(使用pip)从GitHub的包后,并能够将其导入蟒。

与PIP为我工作1.2.1和1.8.4的virtualenv:

$ virtualenv -p python2.7 venv 
Running virtualenv with interpreter /usr/local/bin/python2.7 
New python executable in venv/bin/python 
Installing setuptools............done. 
Installing pip...............done. 

$ source venv/bin/activate 

$ pip install -e git+https://github.com/roberts81/easy-thumbnails.git#egg=easy_thumbnails 
Obtaining easy-thumbnails from git+https://github.com/roberts81/easy-thumbnails.git#egg=easy_thumbnails 
    Cloning https://github.com/roberts81/easy-thumbnails.git to ./venv/src/easy-thumbnails 
    Running setup.py egg_info for package easy-thumbnails 

    no previously-included directories found matching 'docs/_build' 
Installing collected packages: easy-thumbnails 
    Running setup.py develop for easy-thumbnails 

    no previously-included directories found matching 'docs/_build' 
    Creating /Users/jterrace/test/venv/lib/python2.7/site-packages/easy-thumbnails.egg-link (link to .) 
    Adding easy-thumbnails 1.2 to easy-install.pth file 

    Installed /Users/jterrace/test/venv/src/easy-thumbnails 
Successfully installed easy-thumbnails 
Cleaning up... 

$ python 
Python 2.7.3 (default, Nov 12 2012, 09:50:25) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import easy_thumbnails 
>>> easy_thumbnails.VERSION 
'1.2' 
+0

它也与pip v1.3.1一起工作。非常感谢! – slackmart 2014-02-07 19:53:16

虽然它解决了一个不同的问题,下面this Mac OSX 10.8-specific thread其结论似乎是解决这个问题对我来说。

具体来说,我装不分配使用PIP:

$ curl -O http://python-distribute.org/distribute_setup.py 
$ python distribute_setup.py 

然后我说export VIRTUALENV_DISTRIBUTE=1了我的〜/ .bashrc文件,并重新启动我的终端。

我卸载并重新安装了virtualenv和virtualenvwrapper以确保安全。

然后我销毁了旧的虚拟环境并重新创建了它们。无论出于何种原因,修复virtualenv使用和安装分布修复了这个问题。古怪。

+1

这个行为是否有错误报告? – Erik 2013-05-29 23:30:26

+0

Distribute is [now deprecated](https://pypi.python.org/pypi/distribute/0.6.49) - 最好使用setuptools代替。 Dan Tenenbaum的答案似乎更有可能现在起作用,这是我以前在使用旧版pip和setuptools的系统上所做的工作:http://stackoverflow.com/a/38404769/992887 – RichVel 2017-01-06 14:28:22

因为问题已经得到解答,这可能看起来很愚蠢,而且这解决了另一个问题 - 但是当我得到这个错误时,这是​​我的解决方案。 (我希望这可以帮助其他人)

确保你有一个__init__.py文件。结构应该像这样:

/myprojectname 
    /myprojectname 
    __init__.py 
    mymodule.py 
    setup.py 

然后从顶级myprojectname文件夹中运行“pip install -e .”,一切正常。在我的情况下,我忘记了__init__.py,并忘记了这是该消息的可能原因。