繁体   English   中英

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

[英]setup.py build doesn't work but develop does

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

python setup.py develop

但不是在跑步时

python setup.py install

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

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


没有错误,但是*警告我找不到有关......的详细信息 在此输入图像描述


列出但导入将失败 在此输入图像描述


在此输入图像描述

发布这个因为它影响了我。 重要的是要知道构建包的distutils构建它, 即使它已经破坏了依赖关系 ,请参见此处 如果你在运行python setup.py install时观察输出,你可能会发现问题的根源。

对我来说,我有一个名为“what”的软件包,其全名非常清楚它是什么,但输入很烦人。 所以我希望命令本身是一个缩写,就像“我们”。

或者,我的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.
...

问题是没有名为we的模块 ,只有cli工具。 卸下py_modules线,并替换它packages指向全文件夹名解决了这个问题对我来说:

from setuptools import setup

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

现在,当我运行we ,无论执行什么cli包。 希望这有助于未来的读者。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM