Python包似乎忽略了我的要求

时间:2013-06-05 11:36:21

标签: python packaging setuptools distutils pypi

我创建了我的第一个包。当我尝试在新创建的virtualenv中使用pip安装它时,我收到一条错误,指示无法导入库,但它们已添加到install_requires中的setup.py字段中。如果我在vierualenv之外做,一切都好。 我的setup.py在这里:https://github.com/tdi/pyPEPA/blob/dev/setup.py

重现错误:

mkvirtualenv something -p /usr/bin/python3
workon something
pip install pypepa

Downloading/unpacking pypepa
 Running setup.py egg_info for package pypepa
 Traceback (most recent call last):
  File "<string>", line 16, in <module>
  File "/home/tdi/.virtualenvs/koza/build/pypepa/setup.py", line 3, in <module>
    import pypepa
  File "./pypepa/__init__.py", line 6, in <module>
    from pypepa.pepa_model import PEPAModel
  File "./pypepa/pepa_model.py", line 6, in <module>
    from pypepa.parsing.parser import PEPAParser
  File "./pypepa/parsing/parser.py", line 5, in <module>
    from pyparsing import Word, Literal, alphas, alphanums, nums, Combine, Optional, ZeroOrMore, Forward, restOfLine
ImportError: No module named 'pyparsing'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
 File "/home/tdi/.virtualenvs/koza/build/pypepa/setup.py", line 3, in <module>
import pypepa
File "./pypepa/__init__.py", line 6, in <module>
from pypepa.pepa_model import PEPAModel
 File "./pypepa/pepa_model.py", line 6, in <module>
from pypepa.parsing.parser import PEPAParser
 File "./pypepa/parsing/parser.py", line 5, in <module>
  from pyparsing import Word, Literal, alphas, alphanums, nums, Combine, Optional, ZeroOrMore, Forward, restOfLine
 ImportError: No module named 'pyparsing'
 ----------------------------------------
 Command python setup.py egg_info failed with error code 1 in      /home/tdi/.virtualenvs/koza/build/pypepa
 Storing complete log in /home/tdi/.pip/pip.log

2 个答案:

答案 0 :(得分:2)

您的安装脚本导入pypepa,导入pypepa.pepa_model导入pyparsing,但尚未安装pyparsing(我们甚至没有完成运行安装脚本以了解依赖项)。解决方案是在pypepa和setup.py中重复版本号(这样你可以删除导入),或者不在__init __中导入PEPAModel。py。

答案 1 :(得分:0)

Python3使用distutils,setup()将使用requires关键字参数。来自the docs

  

可以通过向setup()提供 requires 关键字参数来指定对其他Python模块和包的依赖性。

setup.py 脚本中的install_requires更改为requires