My project have the following structure:
project/
+ setup.py
+ bobafett/
+ __init__.py
+ __main__.py
+ foo.py
With:
__init__.py
: an empty filefoo.py
: contains the definition ofbar
:
def bar():
print("foo.bar()")
__main__.py
import and usefoo.bar
:
import foo
foo.bar()
✓ Locally, all works well:
~/project $ python3 bobafett/__main__.py
foo.bar()
✗ Once bobafett
is packaged, published and installed, foo
is no longer found
~/project $ python3 setup.py bdist_wheel
~/project $ curl -T ... https://my-pypi.example.com/simple/bobafett/...
~/project $ cd /tmp
/tmp $ pip --index-url https://my-pypi.example.com/simple --user bobafett
/tmp $ python -m bobafett
...
File "/home/ysc/.local/lib/python3.6/site-packages/bobafett/__main__.py", line 1, in <module>
import foo
ModuleNotFoundError: No module named 'foo'
How is that? What can I write instead of import foo
that both works locally and once deployed? Do I need to change my project structure?
setup.py
:
from setuptools import setup
setup(
name='bobafett',
version='1.0.0',
author='YSC',
author_email='ysc@example.com',
packages=['bobafett'],
url='https:///my-pypi.example.com/simple/bobafett/',
description='Prints "foo.bar()".',
)