setup.py构建不起作用,但开发

时间:2016-08-02 20:02:43

标签: python setup.py

我有一个简单的python包,在运行时可以导入而没有问题:

python setup.py develop

但不是在运行时

python setup.py install

运行安装时没有错误*但是当我尝试导入它时出现no module named...错误,即使我在运行pip list时可以看到包。我只安装了python 2.7,我没有使用virtualenv,所以我不明白为什么develop有效但install没有。

(另外运行build然后install也失败了)

没有错误,但是*警告我找不到有关...... 的详细信息 enter image description here

已列出,但导入将失败 enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

发布有关此内容的信息,因为它影响了我。要知道的重要一点是,即使软件包的依赖关系已损坏,构建软件包的distutils也会对其进行编译。,请参见here。如果在运行python setup.py install时看到输出,则可能会确定问题的根源。

对我来说,我有一个名为“ whatever”的程序包,其全名非常清楚,但实际上很烦人。因此,我希望命令本身是缩写,例如“ we”。

最初,我的setup.py看起来像这样:

from setuptools import setup

setup(
    name='we',
    version='3.0.3',
    py_modules=['we'],
    install_requires=[
        ...
    ],
    scripts=['whatever/bin/we']
)

我的文件夹结构如下:

├── setup.py
├── whatever
│   ├── bin/
│   │   ├── we
│   ├── __init__.py
│   ├── other_stuff/

we内,我导入完整的程序包(具有单击界面):

#!/usr/bin/env python

from whatever.cli import cli
cli()

运行安装程序时,我看到了以下内容:

$ python setup.py install
running install
running bdist_egg
running egg_info
writing we.egg-info/PKG-INFO
writing dependency_links to we.egg-info/dependency_links.txt
writing requirements to we.egg-info/requires.txt
writing top-level names to we.egg-info/top_level.txt
file we.py (for module we) not found
reading manifest file 'we.egg-info/SOURCES.txt'
writing manifest file 'we.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.13-x86_64/egg
running install_lib
running build_py
file we.py (for module we) not found
file we.py (for module we) not found
warning: build_py: byte-compiling is disabled, skipping.
...

问题在于,没有名为我们的 module ,只有cli工具。删除py_modules行并将其替换为packages,指向完整的 package 文件夹名称对我来说解决了这一问题:

from setuptools import setup

setup(
    name='we',
    version='3.0.3',
    packages=['whatever'],
    install_requires=[
        ...
    ],
    scripts=['whatever/bin/we']
)

现在,当我运行we时,将执行任何cli软件包。希望这对以后的读者有所帮助。

相关问题