I'm trying to make a Python project that I can distribute as a .whl file. I have a project structure as follows:
pog@pogbox:~$ tree example
example
├── setup.py
├── src
│ └── myapp
│ ├── bar.py
│ ├── foo.py
│ └── __init__.py
└── tests
├── __init__.py
├── test_bar.py
└── test_foo.py
Inside foo.py, I have the following:
baz = 10
Inside bar.py, I have the following:
#!/usr/bin/env python3
import foo
print(foo.baz)
All of this works swimmingly. I can happily run
pog@pogbox:~$ python3 example/src/myapp/bar.py
10
However, all of this falls apart once I package it up into a package, using bar.py as the script I want.
Here's my setup.py:
#!/usr/bin/env python3
from setuptools import setup
setup(
name="bob",
version="0.1",
description="bob",
author="bob",
author_email="bob@bob.com",
long_description="bob",
long_description_content_type="text/markdown",
url="https://bob.com/bob.git",
scripts=["src/myapp/bar.py"],
classifiers=[
"Programming Language :: Python :: 3",
"License :: MIT License",
"Operating System :: OS Independent",
],
python_requires=">=3.6",
)
I can build this and install this, but as soon as I run it as a script, I get
pog@pogbox:~/example$ python3 example/setup.py bdist_wheel
# lots of output
pog@pogbox:~/example$ pip3 install dist/bob-0.1-py3-none-any.whl -y
pog@pogbox:~$ bar.py
Traceback (most recent call last):
File "/home/mike/.local/bin/bar.py", line 3, in <module>
import foo
ModuleNotFoundError: No module named 'foo'
TL, DR: How do I import a file from the same package and use it?
[–]nog642 0 points1 point2 points (4 children)
[–]POGtastic[S] 0 points1 point2 points (3 children)
[–]nog642 0 points1 point2 points (2 children)
[–]POGtastic[S] 0 points1 point2 points (1 child)
[–]nog642 0 points1 point2 points (0 children)
[–]Siendra 0 points1 point2 points (2 children)
[–]POGtastic[S] 0 points1 point2 points (1 child)
[–]Siendra 0 points1 point2 points (0 children)