I have a tiny test project to learn the fundamentals for creating a local module that is shared between other dependent projects of mine. When I try to execute the depending project file it errors claiming "ModuleNotFoundError".
This is the structure :
#Example module to be used by the app
/BarMod
/BarMod/__init__.py
/BarMod/BarMod.py
/BarMod/setup.py
#Example app to use the module
/FizzApp
/FizzApp/fizz.py
BarMod/init.py is empty
BarMod/BarMod.py
def foofunc(x):
'''The module function I want to have access to'''
return x+1
BarMod/setup.py
from setuptools import setup, find_packages
setup(
name="BarMod",
version="1.0",
packages=find_packages(),
)
FizzApp/fizz.py
import BarMod
print(BarMod.BarMod.foofunc(1))
After setting up the files as described I create a virtual environment adjacent to FizzApp and activate it. I will then run 'pip install ./BarMod' which yields the following output :
Processing c:\users\fizzyfoo\documents\github\foobar\barmod
DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
Using legacy 'setup.py install' for BarMod, since package 'wheel' is not installed.
Installing collected packages: BarMod
Running setup.py install for BarMod ... done
Successfully installed BarMod-1.0
WARNING: You are using pip version 21.2.3; however, version 21.2.4 is available.
You should consider upgrading via the 'C:\Users\TRLew\Documents\GitHub\Foobar\FizzApp\env\Scripts\python.exe -m pip install --upgrade pip' command.
Aside from deprecation warnings this appears to mean that it installed successfully.
From here if I try running FizzApp/fizz.py with this venv I get the ModuleNotFoundError.
What am I missing from this setup to get it to run?
Bonus : How do I make this so it won't go belly up once the deprecation sets in? ( bonus is answered via ( https://stackoverflow.com/a/67301782/1858582 ) )
References I used :
https://packaging.python.org/guides/tool-recommendations/
UPDATE
If I use the REPL I can import BarMod as prescribed above but it lacks the foofunc method.
>>> import BarMod
>>> dir(BarMod)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
If I then add "from .BarMod import foofunc" to the init.py file in BarMod the function becomes available while in the REPL.
>>> import BarMod
>>> dir(BarMod)
['BarMod', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'foofunc']
I still can't load the module while using the same venv in fizz.py.