0

I have a project with these contents:

proj
├── src
│   ├── scriptA.py
│   ├── scriptB.py
│   └── __init__.py
├── LICENCE
├── README.md
└── setup.py

I am following this guide to package this project for PiPY. The setup.py file looks like:

#!/usr/bin/python3
# coding=utf8

from setuptools import setup

setup(
    name = "proj",
    version = "0.2",
    packages = ['src'],
    install_requires=[],
    entry_points={
        'console_scripts': [
            'scriptA=src:scriptA',
            'scriptB=src:scriptB'
        ],
    },

    # metadata for upload to PyPI
    author = "Luís",
    author_email = "[email protected]",
    description = "Some package",
    license = "EUPL v1.1",
    keywords = "pip package",
    url = "https://some.place.com",   # project home page, if any
    classifiers = [
        "Programming Language :: Python",
        "Programming Language :: Python :: 3",
        "Development Status :: 4 - Beta",
        "Environment :: Console",
        "Intended Audience :: Science/Research",
        "License :: OSI Approved :: European Union Public Licence 1.1 (EUPL 1.1)",
        "Operating System :: OS Independent",
        "Topic :: Scientific/Engineering :: GIS"
        ],


    # could also include long_description, download_url, classifiers, etc.
)

The __init__.py file contains the following:

__all__ = ["scriptA", "scriptB"]

The scripts just print text messages. This is scriptA.py:

def main():
    print ("This is scriptA!")

main()

The packages is building sucessfully:

$ python3 setup.py bdist_wheel --universal
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/src
copying src/scriptA.py -> build/lib/src
copying src/__init__.py -> build/lib/src
copying src/scriptB.py -> build/lib/src
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/src
copying build/lib/src/scriptA.py -> build/bdist.linux-x86_64/wheel/src
copying build/lib/src/__init__.py -> build/bdist.linux-x86_64/wheel/src
copying build/lib/src/scriptB.py -> build/bdist.linux-x86_64/wheel/src
running install_egg_info
running egg_info
creating proj.egg-info
writing proj.egg-info/PKG-INFO
writing top-level names to proj.egg-info/top_level.txt
writing entry points to proj.egg-info/entry_points.txt
writing dependency_links to proj.egg-info/dependency_links.txt
writing manifest file 'proj.egg-info/SOURCES.txt'
reading manifest file 'proj.egg-info/SOURCES.txt'
writing manifest file 'proj.egg-info/SOURCES.txt'
Copying proj.egg-info to build/bdist.linux-x86_64/wheel/proj-0.1.egg-info
running install_scripts
creating build/bdist.linux-x86_64/wheel/proj-0.1.dist-info/WHEEL

I then installed it in a Python 3 virtual environment:

$ source ~/.virtualenvs/test_p3/bin/activate
(test_p3)$ python setup.py install
running install
running bdist_egg
running egg_info
writing dependency_links to proj.egg-info/dependency_links.txt
writing proj.egg-info/PKG-INFO
writing entry points to proj.egg-info/entry_points.txt
writing top-level names to proj.egg-info/top_level.txt
reading manifest file 'proj.egg-info/SOURCES.txt'
writing manifest file 'proj.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/src
copying build/lib/src/scriptA.py -> build/bdist.linux-x86_64/egg/src
copying build/lib/src/__init__.py -> build/bdist.linux-x86_64/egg/src
copying build/lib/src/scriptB.py -> build/bdist.linux-x86_64/egg/src
byte-compiling build/bdist.linux-x86_64/egg/src/scriptA.py to scriptA.cpython-34.pyc
byte-compiling build/bdist.linux-x86_64/egg/src/__init__.py to __init__.cpython-34.pyc
byte-compiling build/bdist.linux-x86_64/egg/src/scriptB.py to scriptB.cpython-34.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying proj.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying proj.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying proj.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying proj.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying proj.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/proj-0.1-py3.4.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing proj-0.1-py3.4.egg
Copying proj-0.1-py3.4.egg to /home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages
Adding proj 0.1 to easy-install.pth file
Installing scriptA script to /home/desouslu/.virtualenvs/test_p3/bin
Installing scriptB script to /home/desouslu/.virtualenvs/test_p3/bin

Installed /home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/proj-0.1-py3.4.egg
Processing dependencies for proj==0.1
Finished processing dependencies for proj==0.1

But when I run one of the scripts I get the following:

(test_p3)$ scriptA
Traceback (most recent call last):
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 2051, in load
    entry = getattr(entry,attr)
AttributeError: 'module' object has no attribute 'scriptA'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/desouslu/.virtualenvs/test_p3/bin/scriptA", line 9, in <module>
    load_entry_point('proj==0.1', 'console_scripts', 'scriptA')()
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 353, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 2321, in load_entry_point
    return ep.load()
  File "/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/pkg_resources.py", line 2053, in load
    raise ImportError("%r has no %r attribute" % (entry,attr))
ImportError: <module 'src' from '/home/desouslu/.virtualenvs/test_p3/lib/python3.4/site-packages/hex_utils-0.2-py3.4.egg/src/__init__.py'> has no 'scriptA' attribute

What is exactly causing this error?

2 Answers 2

2

In your case it looks for scriptA callable in module src.

Looking at the docs, entry_points should be defined like:

entry_points={
    'console_scripts': [
        'scriptA=src.scriptA:main_func',
        'scriptB=src.scriptB:main_func'
    ],
},
Sign up to request clarification or add additional context in comments.

7 Comments

These scripts have no functions, just some prints (this is a test package). What should then be the entry points?
You should create a function with code to be executed and put the function name into the entry_points declaration.
From the docs > The functions you specify are called with no arguments, and their return value is passed to sys.exit(), so you can return an errorlevel or message to print to stderr.
I modified setup.py and the scripts as you indicated. Now I get a different error when I run the srcipt: ImportError: No module named 'src.scriptA'
After installing the package in the virtual environment, does import src work?
|
-1

You should declarate your classes in __init__.py follow link

2 Comments

Both scripts are declared in __init__.py.
You need to add markup around __init__.py otherwise the underscores will be treated as a signal to make the word bold. You can do that by using the backtick as a quote at the beginning and end of the filename.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.