0

I have a package with the following directory structure:

mypackage
   mypackage
      __init.py__
      users.py
   bin
      mypackage.py
   setup.py

My setup.py looks like this:

from setuptools import setup, find_packages

setup(
    name='mypackage.py',
    version='0.9',
    packages=find_packages(),
    scripts=['bin/mypackage.py'],
    install_requires=['np', 'filelock', 'python-dateutil', 'requests', 'numpy'])

The __init__.py contains:

import mypackage.users

My bin/mypackage.py includes among other things:

from mypackage.users import *

I am running

python3 setup.py install

Everything works great and then on the terminal I type:

mypackage.py

and I am greeted with the following error:

    from mypackage.users import *
ImportError: No module named 'mypackage.users'; 'mypackage' is not a package

If I attempt:

python3
import mypackage

I get no errors. I also use virtualenv (not shown here) but I am sure there are no other conflicts.

6
  • Does it work if you do name='mypackage' without the tailing .py? Probably would need to uninstall and reinstall to test. Commented Apr 20, 2018 at 21:07
  • Also, recommend using pip install -e ., but I don't think that would change anything in this case Commented Apr 20, 2018 at 21:08
  • Changing the name made no difference. pip install -e . is indeed much better but still no effect. It does uninstall and reinstall the module though successfully. Commented Apr 20, 2018 at 21:19
  • I added some additional info about the fact that through interactive pyhton I can import the package. It is only through my script that I cannot Commented Apr 20, 2018 at 21:22
  • Alright I managed to figure out what was happening. The script name was the same like the module name and that confused things. When renamed the script name to mypackagecli.py it resolves this issue. However, I have a follow up issue, when testing the tool, the command line tool won't find the mypackage.users unless it is already installed. But If I am programming, how can I quickly test changes on the code without having to install everytime? Commented Apr 20, 2018 at 21:37

1 Answer 1

7

Long story short, executable script cannot have the same name like the package. Lost 3 hours of my life.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.