16

I'm having trouble installing one of my python scripts. It has the following structure:

myproject
  setup.py
  src
    myproject
      otherfolders
      main.py
      __init__.py

And my setup.pycreates an entry point like this:

from setuptools import setup, find_packages

setup(name='mypackage',
version='2.4.0',
author='me',
author_email='...',
package_dir={'':'src'},
packages=find_packages('myproject'),
install_requires=[
    "networkx",
    "geopy",
    "pyyaml"
],
zip_safe=False,
entry_points={
    'console_scripts': [
        'myproject=myproject.main:main',
    ],
},
)

Now, after installing this successfully with sudo python setup.py install, I run mypackage and get an import error: No module named mypackage.main.

I am aware that there are lots of similar questions and I tried most/all solutions suggested here, e.g., checking the __init__.py and setting PYTHONPATH, but the problem still exists. I'm running this on two different Ubuntu 16.04 machines.

I'm pretty sure this worked before, but even when I go back to an earlier commit it doesn't work now.

I noticed the installation works with develop but still fails with install. Does that make sense to anyone?

CGFoX
  • 4,294
  • 5
  • 39
  • 69
  • Which Python version are you targeting? Currently it's 2.7 – Xantium Mar 15 '18 at 09:49
  • The script is written in Python 3.5. I also tried installing it with `sudo python3 setup.py install` (also successful), but when I run it, I get a similar error: `ModuleNotFoundError: No module named 'myproject` – CGFoX Mar 15 '18 at 09:52
  • 4
    python setup.py stuff is the worst thing about python. – The Unfun Cat May 09 '18 at 11:51

2 Answers2

8

The problem was in find_packages():

Some projects use a src or lib directory as the root of their source tree, and those projects would of course use "src" or "lib" as the first argument to find_packages().

Hence, I had to change find_packages('myproject') to find_packages('src').

CGFoX
  • 4,294
  • 5
  • 39
  • 69
0

packages=find_packages('mypackage') -> packages=find_packages('myproject').

Also you should use myproject.main.

Zheka Koval
  • 527
  • 4
  • 10
  • You're right. But that was just a typo when copying it to stackoverflow. It's correct in my git. I edited the question – CGFoX Mar 15 '18 at 10:04