简体   繁体   中英

setup.py build doesn't work but develop does

I have a simple python package that's importable without issue when running:

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 . I only have python 2.7 installed, I'm not using virtualenv, so I don't understand why develop works but install doesn't.

(additionally running build then install also fails)


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 . If you watch the output when you run python setup.py install you will probably identify the source of the problem.

For me, I had a package called "whatever" with a full name that was very clear what it was, but is annoying to type. So I wanted the command itself to be an abbreviation, like "we".

Orginally, my setup.py looked like this:

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):

#!/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. Removing the py_modules line and replacing it with packages pointing the full package folder name solved it for me:

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. Hope this helps any future readers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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