[英]setup.py build doesn't work but develop does
I have a simple python package that's importable without issue when running: 我有一个简单的python包,在运行时可以导入而没有问题:
python setup.py develop
but not when running 但不是在跑步时
python setup.py install
No error occurs* when running install but I get a no module named...
error when I attempt to import it even though I can see the package when I run pip list
. 运行安装时没有错误*但是当我尝试导入它时,我得到一个
no module named...
错误,即使我在运行pip list
时可以看到包。 I only have python 2.7 installed, I'm not using virtualenv, so I don't understand why develop
works but install
doesn't. 我只安装了python 2.7,我没有使用virtualenv,所以我不明白为什么
develop
工作但install
没有。
(additionally running build
then install
also fails) (另外运行
build
然后install
也失败)
No error but a *warning I couldn't find details about... 没有错误,但是*警告我找不到有关......的详细信息
Listed but importing will fail 列出但导入将失败
Posting about this since it affected me. 发布这个因为它影响了我。 The important thing to know is that distutils which builds the package builds it even though it has broken dependencies , see here .
重要的是要知道构建包的distutils构建它, 即使它已经破坏了依赖关系 ,请参见此处 。 If you watch the output when you run
python setup.py install
you will probably identify the source of the problem. 如果你在运行
python setup.py install
时观察输出,你可能会发现问题的根源。
For me, I had a package called "whatever" with a full name that was very clear what it was, but is annoying to type. 对我来说,我有一个名为“what”的软件包,其全名非常清楚它是什么,但输入很烦人。 So I wanted the command itself to be an abbreviation, like "we".
所以我希望命令本身是一个缩写,就像“我们”。
Orginally, my setup.py looked like this: 或者,我的setup.py看起来像这样:
from setuptools import setup
setup(
name='we',
version='3.0.3',
py_modules=['we'],
install_requires=[
...
],
scripts=['whatever/bin/we']
)
Where my folder structure was like this: 我的文件夹结构是这样的:
├── setup.py
├── whatever
│ ├── bin/
│ │ ├── we
│ ├── __init__.py
│ ├── other_stuff/
and inside we
, I import the full package (that has a click interface): 在
we
内部,我导入完整的包(具有点击界面):
#!/usr/bin/env python
from whatever.cli import cli
cli()
When I ran the install I saw this: 当我运行安装时,我看到了这个:
$ 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.
...
The problem was that there was no module named we, only the cli tool. 问题是没有名为we的模块 ,只有cli工具。 Removing the
py_modules
line and replacing it with packages
pointing the full package folder name solved it for me: 卸下
py_modules
线,并替换它packages
指向全包文件夹名解决了这个问题对我来说:
from setuptools import setup
setup(
name='we',
version='3.0.3',
packages=['whatever'],
install_requires=[
...
],
scripts=['whatever/bin/we']
)
Now when I run we
, the whatever cli package executes. 现在,当我运行
we
,无论执行什么cli包。 Hope this helps any future readers. 希望这有助于未来的读者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.