Python pip找不到安装文件
我在尝试使用pip安装python包时出错 卸载包后,它正在某个目录中查找“setup.py”,但在那里找不到它。setup.py文件实际上是向下一个目录 它在看:Python pip找不到安装文件,python,virtualenv,pip,Python,Virtualenv,Pip,我在尝试使用pip安装python包时出错 卸载包后,它正在某个目录中查找“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.p
'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
有没有办法让pip知道包中的这个嵌套文件夹结构
谢谢我添加了一个小函数,并在pip/req.py文件的setup\u 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')
- 修复包以遵循标准包布局,即,
应位于顶部目录中setup.py
- 将归档文件解压并将
指向带有pip
文件的目录setup.py
\u文件
))
也许您可以从virtualenvs/pyling/build/nltk/调用pip,其中应该是virtualenvs/pyling/build/nltk/nltk-2.0b9/?然后添加我所做的。我发现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__)
#! /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__)
它可能很脆弱,但应该继续工作,直到pip更改它生成的命令行python代码为止我遇到了类似的问题,并放弃了使用pip的默认URL。但是,如果您只想安装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
pip安装-E PyYAML#如果您还没有这样做
pip安装-E--无索引--查找链接=http://nltk.googlecode.com/ nltk
我想您知道您可以卸载它,然后自己运行python setup.py install
是的,我知道这一点。只是我宁愿使用pip开箱即用,这样我就可以将pip冻结用于需求文件,也可以制作一个捆绑包与其他人共享。我希望在我的目标virtualenv中可以从任何目录调用pip。大多数时候,软件包甚至还没有下载或解包,因此还没有setup.py文件。这可以通过执行:source/path/to/your/virtualenv/bin/activate来完成(每个打开的shell只需要一次)和pip install/path/to/package或/path/to/your/virtualenv/bin/pip/path/to/package是的,我已经在问题点激活了。我明白你关于路径的观点,但是如果包还没有下载(pip为你做了),那么就没有路径可供参考。我想我想通过使用--dowload only选项,然后作为第二步安装,让它在一步而不是第二步中工作。我的解决方案允许我在下载任何东西之前进行一步pip安装,所以这是我喜欢的。冻结似乎仍然有效,但还没有捆绑,假设它也可以。