0

I have a very simple project example that I can't get to work.

I have a setup.py that looks like this:

from setuptools import setup

install_requires=['numpy','matplotlib','pyusb']

setup(
      name='TestInstall',
      version='1.0',
      description='a test',
      author='Pete',
      author_email='pete@hotmail.com',
      url='https://github.com',
      packages=['App'],
      install_requires=install_requires,
      entry_points={
        'console_scripts': [
            'TestInstall = App.Test:main']}
      )

I have a directory call 'App' and within this directory, I have two files:

__init__.py:

import Test

and Test.py:

def main():
    print 'Hi There'

if __name__ == '__main__':
    main()

I run 'python setup.py install', which seems to run just fine:

sudo -H python setup.py install
[sudo] password for pete: 
running install
running bdist_egg
running egg_info
creating TestInstall.egg-info
writing requirements to TestInstall.egg-info/requires.txt
writing TestInstall.egg-info/PKG-INFO
writing top-level names to TestInstall.egg-info/top_level.txt
writing dependency_links to TestInstall.egg-info/dependency_links.txt
writing entry points to TestInstall.egg-info/entry_points.txt
writing manifest file 'TestInstall.egg-info/SOURCES.txt'
reading manifest file 'TestInstall.egg-info/SOURCES.txt'
writing manifest file 'TestInstall.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-i686/egg
running install_lib
running build_py
creating build
creating build/lib.linux-i686-2.7
creating build/lib.linux-i686-2.7/App
copying App/Test.py -> build/lib.linux-i686-2.7/App
copying App/__init__.py -> build/lib.linux-i686-2.7/App
creating build/bdist.linux-i686
creating build/bdist.linux-i686/egg
creating build/bdist.linux-i686/egg/App
copying build/lib.linux-i686-2.7/App/Test.py -> build/bdist.linux-i686/egg/App
copying build/lib.linux-i686-2.7/App/__init__.py -> build/bdist.linux-i686/egg/App
byte-compiling build/bdist.linux-i686/egg/App/Test.py to Test.pyc
byte-compiling build/bdist.linux-i686/egg/App/__init__.py to __init__.pyc
creating build/bdist.linux-i686/egg/EGG-INFO
copying TestInstall.egg-info/PKG-INFO -> build/bdist.linux-i686/egg/EGG-INFO
copying TestInstall.egg-info/SOURCES.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying TestInstall.egg-info/dependency_links.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying TestInstall.egg-info/entry_points.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying TestInstall.egg-info/requires.txt -> build/bdist.linux-i686/egg/EGG-INFO
copying TestInstall.egg-info/top_level.txt -> build/bdist.linux-i686/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/TestInstall-1.0-py2.7.egg' and adding 'build/bdist.linux-i686/egg' to it
removing 'build/bdist.linux-i686/egg' (and everything under it)
Processing TestInstall-1.0-py2.7.egg
Copying TestInstall-1.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adding TestInstall 1.0 to easy-install.pth file
Installing TestInstall script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/TestInstall-1.0-py2.7.egg
Processing dependencies for TestInstall==1.0
Searching for pyusb==1.0.0
Best match: pyusb 1.0.0
Adding pyusb 1.0.0 to easy-install.pth file

Using /usr/local/lib/python2.7/dist-packages
Searching for matplotlib==1.5.1
Best match: matplotlib 1.5.1
matplotlib 1.5.1 is already the active version in easy-install.pth

Using /usr/lib/python2.7/dist-packages
Searching for numpy==1.11.0
Best match: numpy 1.11.0
numpy 1.11.0 is already the active version in easy-install.pth

Using /usr/lib/python2.7/dist-packages
Finished processing dependencies for TestInstall==1.0
pete@pete-ThinkPad-T60p:~/Work/TestInstall$ 

But when I try to run the program:

TestInstall

I get:

pete@pete-ThinkPad-T60p:~/Work/TestInstall$ TestInstall
Traceback (most recent call last):
  File "/usr/local/bin/TestInstall", line 9, in <module>
    load_entry_point('TestInstall==1.0', 'console_scripts', 'TestInstall')()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 542, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2569, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2229, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2235, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named Test
pete@pete-ThinkPad-T60p:~/Work/TestInstall$ 

This must be a simple error, but I've looked everywhere and am pulling my hair out.

Thanks in advance for any answers. Pete

BTW, I see the .egg file in /usr/local/lib/python2.7/dist-packages and within it, I see the EGG-INFO listing the sources, entry point, etc. listed, along with App directory, and under it, my __init__.py and .pyc file and my Test.py and .pyc file.

Pete P
  • 1,048
  • 7
  • 12
  • Cannot reproduce under Python 2.7.5 with setuptools 36.0.1. What version of setuptools are you using? Is there possibly another package or module named `App` in `sys.path`? – jwodder Jun 08 '17 at 21:37
  • same version. Are you saying that after installation, that when you type 'TestInstall', it prints 'Hi there'? Also, if you're knowledgeable about this topic, does it look right what I'm doing? – Pete P Jun 08 '17 at 21:44
  • Yes, that's what happens, and what you're doing looks right (although `pip install .` is preferred over `python setup.py install` for [the reasons given here](https://stackoverflow.com/q/3220404/744178)). If you do `import App; App.__file__` in the Python interpreter, does the path point to the package you installed or another `App`? – jwodder Jun 08 '17 at 22:13
  • Wow - I think I see the problem, but am not understanding something! I have many projects with this same structure (i.e. a directory named after the project with an App directory underneath containing the GUI portion of the application. And I install all of these projects this way with a similar setup.py file (I paired this one down to only the details that don't work). In any case, when I do what you said (import App and print App.__file__), the file shown is to another previously installed project with this similar structure! Does this mean my directories have to be uniquely named? – Pete P Jun 09 '17 at 12:29
  • I changed the name of the directory 'App' to something unique, like 'TestInstallApp' (along with all changes in setup.py) and now it works! I'm hoping someone can explain this and clarify the rules for this and the standard practice - apparently, directories within projects must be uniquely named! – Pete P Jun 09 '17 at 12:44
  • Yes, they have to be uniquely named; otherwise, how would Python know which `App` you're referring to when doing `import App`? The project name is only used for installing & uninstalling, not when importing. – jwodder Jun 09 '17 at 14:10
  • This is a serious misunderstanding on my part and in my opinion, this is the wrong functionality (but it is what it is). I believe that the rules for the installer work well for installing Python Modules (i.e. libraries) that a user would access by using import from within his application), but is wrong behavior for installing applications, which are simply run from the command line. The fact that the installer builds a script that finds my application by looking in the Python path is just wrong - I told it exactly where it is relative to my project. My opinion. But I'm glad I know now! – Pete P Jun 09 '17 at 17:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/146287/discussion-between-pete-p-and-jwodder). – Pete P Jun 09 '17 at 17:06

0 Answers0