2011-03-15 150 views
4

我试图用pip安装python软件包时出现错误。pip没有找到安装文件

解开软件包后,它在某个目录中查找“setup.py”,并且在那里找不到它。 setup.py文件实际上是一个目录。

它在寻找:

'virtualenvs/pyling/build/nltk/setup.py' 

但它实际上是在:

virtualenvs/pyling $ ls build/nltk/nltk-2.0b9/ 
INSTALL.txt javasrc LICENSE.txt nltk PKG-INFO README.txt setup.py 

有没有一种方法,使点子意识到在这个包嵌套文件夹结构?

感谢

+0

我假设你知道你可以解开它,并自己运行'python setup.py install'? – 2011-03-15 22:28:26

+1

是的,我知道这一点。只是我宁愿使用pip,因为我可以使用pip冻结需求文件以及制作一个包与其他人共享。 – dave 2011-03-16 17:01:54

回答

0

我增加了一个小功能,并调用它的属性定义在PIP/req.py文件setup_py。

这似乎使它按我期望的方式工作,即如果setup.py文件只有一层更深。希望捆绑和冻结时,没有得到破获...

import os 

def get_setup_path(in_path): 
    print "starting path is %s"%in_path 
    fileList=os.listdir(in_path) 
    if fileList.__contains__("setup.py"): 
     print "setup.py is indeed there" 
     return in_path 
    for f in fileList: 
     f=os.path.join(in_path,f) 
     if os.path.isdir(f): 
      contents=os.listdir(f) 
      if contents.__contains__("setup.py"): 
       out_path=os.path.join(in_path,f) 
       return out_path 
    print "could not find setup.py by looking one level deeper" 
    return in_path 

,然后在这里调用它req.py

(around line 195 in req.py) 
@property 
def setup_py(self): 
    self.source_dir= get_setup_path(self.source_dir) 
    return os.path.join(self.source_dir, 'setup.py') 
0
  • 修复包遵循标准的封装布局即setup.py应在顶层目录中。

  • 解压存档和点pipsetup.py文件的目录。
+0

我的解决方案允许我在下载任何东西之前先做一步安装,这是我更喜欢的。冻结似乎仍然有效,但尚未捆绑,假设它也可以。 – dave 2011-03-17 14:07:03

0

我从一个setup.py是在不同的目录中调用PIP的时候就已经有这个问题的解决方法是加入以下的setup.py:

进口OS os.chdir( os.path.dirname(os.path.abspath则(__file__)))

也许你打电话从virtualenvs PIP/pyling /编译/ NLTK /它应该是virtualenvs/pyling /编译/ NLTK/NLTK-2.0b9/?然后,只需添加我所做的。

+0

我希望能够在我的目标虚拟环境中从任何目录调用点子。该软件包甚至没有下载或解压,但大部分时间没有setup.py文件。 – dave 2011-03-17 14:05:50

+0

这可以通过执行以下命令来完成:source/path/to/your/virtualenv/bin/activate(每个打开的shell只需要一次)AND pip install/path/to/package OR/path/to/your/virtualenv/bin /点/路径/到/包 – 2011-03-18 12:38:18

+0

是的,我已经在问题点激活。我看到你关于路径的观点,但是如果这个软件包还没有下载(哪个pip为你做的),那么目前还没有可供参考的路径。我想我想通过使用--download-only选项,然后安装作为第二步,在一步不是2。 – dave 2011-03-21 15:06:31

1

我发现的是,PIP运行一个python命令行脚本,看起来像这样:

__file__ = '<path to package>/setup.py' 

from setuptools.command import egg_info 

def replacement_run(self): 
    self.mkpath(self.egg_info) 

    installer = self.distribution.fetch_build_egg 

    for ep in egg_info.iter_entry_points('egg_info.writers'): 
     # require=False is the change we're making: 

     writer = ep.load(require=False) 

     if writer: 
      writer(self, ep.name, egg_info.os.path.join(self.egg_info,ep.name)) 

    self.find_sources() 

egg_info.egg_info.run = replacement_run 

execfile(__file__) 

在包的顶级目录,其中没有setup.py,我把一个setup.py那转载此行为,但chdir'd包含“真正的”setup.py目录,并在最后执行,而不是。

唯一的另一个问题是,pip创建了一个目录“pip-egg-info”,它期望被填充,需要在“real”setup.py目录中创建一个符号链接。

新的顶级设置。吡啶是这样的:

#! /usr/bin/env python 

from os import chdir, symlink, getcwd 
from os.path import join, basename, exists 

filename = basename(__file__) 

chdir("python") 

setupdir = getcwd() 

egginfo = "pip-egg-info" 

if not exists(egginfo) and exists(join("..", egginfo)): 
    symlink(join("..", egginfo), egginfo) 

__file__ = join(setupdir, filename) 

from setuptools.command import egg_info 

def replacement_run(self): 
    self.mkpath(self.egg_info) 

    installer = self.distribution.fetch_build_egg 

    for ep in egg_info.iter_entry_points('egg_info.writers'): 
     # require=False is the change we're making: 

     writer = ep.load(require=False) 

     if writer: 
      writer(self, ep.name, egg_info.os.path.join(self.egg_info,ep.name)) 

    self.find_sources() 

egg_info.egg_info.run = replacement_run 

execfile(__file__) 

这也可能是脆弱的,但应该继续工作,直到画中画改变,它的产生

0

我有类似的问题,放弃了对使用的默认网址,PIP在命令行Python代码。但是,如果你只是想安装nltk,这对我有用:

pip install -E <virtualenv-dir> PyYAML #if you have not done so 
pip install -E <virtualenv-dir> --no-index --find-links=http://nltk.googlecode.com/ nltk