12

My package has a entry point defined in it's setup.py:

# -*- coding: utf-8 -*-
from setuptools import setup

setup(
    name='fbuildbot',
    version='0.1',
    ...
    entry_points={
        'console_scripts': [
            'create = create:main',
        ],
    },
    install_requires=[
        "cookiecutter",
    ],
)

Thing is, If I do python setup.py develop, I can run the command just fine, but if I do install it with python setup.py install the install procedure runs correctly but the console script fails with ImportError:

Traceback (most recent call last):
  File "/home/matias/.venvs/fbuild/bin/create", line 8, in <module>
    load_entry_point('fbuildbot==0.1', 'console_scripts', 'create')()
  File "/home/matias/.venvs/fbuild/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point
  File "/home/matias/.venvs/fbuild/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2221, in load_entry_point
  File "/home/matias/.venvs/fbuild/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1954, in load
ImportError: No module named create

Clearly it's failing to setup the package correctly on the pythonpath. I thought it was because I have the script barely at the top level. So I tried adding wrapping it all in a package, moving all important parts to a inner module and changing the setup.py accordingly:

# -*- coding: utf-8 -*-
from setuptools import setup

setup(
    name='fbuildbot',
    version='0.1',
    description="Buildbot configuration generator for fbuild",
    ...
    packages=['fbuildbot', ],
    entry_points={
        'console_scripts': [
            'create = fbuildbot.create:main',
        ],
    },
    install_requires=[
        "cookiecutter",
    ],
)

But it fails with the same message (with updated path, obviously).

Clearly I'm doing something wrong here. What could it be?

2 Answers 2

15

The problem is in your packages argument. You only specify:

packages=['fbuildbot', ],

not

packages=['fbuildbot', 'fbuildbot.create'],

so your setup is not actually installing the "create" module. Makes sense that it could not be found.

I would recommend the find_packages utility

from setuptools import setup, find_packages

setup(
    ...
    packages=find_packages(),
    entry_points={
        'console_scripts': [
            'create = fbuildbot.create:main',
        ],
    },
    ...
)

which will handle all of it for you.

Sign up to request clarification or add additional context in comments.

Comments

0

To ensure that command line modules/scripts are included in your Python package distribution, especially when find_packages() doesn't capture all necessary files, you can utilize a MANIFEST.in file.

This file allows you to specify additional files to include in your source distribution and will solve the ModuleNotfoundError.

Create MANIFEST.in and place this file in the root directory of your project alongside setup.py.

Specify .py files to include within the MANIFEST.in For example:

include fbuildbot/create.py
recursive-include fbuildbot *

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.