I am playing around with the ability to create custom packages in Python. To do this I have created an extremely simple package. The directory structure is:
__init__.py
myfol1/
__init__.py
myfol2/
__init__.py
myfol3/
__init__.py
myfuncs.py
.gitignore
setup.py
Contents of setup.py
:
import setuptools
setuptools.setup(
name='myfol1',
version='0.0.3',
packages=['myfol1']
)
Contents of myfuncs.py
:
def calc_addition(a,b):
return a+b
All of the __init__.py
files are empty.
Now I am trying to include the above in a different repo. To do this I have told this other repo to install the package, by adding the following line to my requirements.txt. The below line just tells it to install from the Git repo at https://github.com/eliot1785/import_example. (The reason I'm doing that is that in actuality I am testing the process for installing from a private GitHub repo, so putting it in PyPI isn't an option here.):
git+https://github.com/eliot1785/import_example.git@0.0.3
After running pip install -r requirements.txt
I can see the package being installed.
Now here is the problem. import myfol1
works, or at least it doesn't raise an error in VSCode. But the moment I try to do what I actually want to do, which is add the subdirectories like from myfol1.myfol2.myfol3.myfuncs import calc_addition
, it won't work because the import cannot be resolved. Similarly as soon as I type import myfol1.myfol2
I start seeing an error in VSCode.
This seems so simple but I'm obviously missing something. I can't figure out where I have gone wrong. Every answer I've seen so far suggests that adding __init__.py
would be sufficient, but it just isn't working for me. Any help you can provide would be greatly appreciated.