'`ModuleNotFoundError` When Importing Python Package from Git
I'm attempting to install a featurestore
package from a private GitHub repo via ssh with the following command:
pip3 install -U git+ssh://git@dsghe.<mydomain>/bshelton/package_test.git@master#egg=featurestore
The install is successful, per the image below:
But when trying to run from featurestore import *
, I get a ModuleNotFoundError: No module named 'featurestore'
error.
Using pip3 freeze
, I see that the package is installed, but not with the <package>==<version>
syntax I would expect, but it seems to be referencing the git commit instead as its "version":
I believe that the repo's directory set-up is appropriate for a Python package, per the screenshot below.
A noticeable difference between this package's install and the other packages I've installed is that it seems like only the ...dist-info
folder is installed for my featurestore
package, while every other installed package includes the actual package directory, in addition to the ...dist-info
folder. Using ls ~/.local/lib/python3.6/site-packages
:
This is my first time, trying to create a package like this, and I've been referencing the several sources below, but would appreciate some insight from the community as to what I'm missing. Thanks.
Solution 1:[1]
The cause of my issue turned out to be a syntax error in my setup.cfg above the package_dir
and packages
lines, which are important if using a package layout with 'src'. Until I fixed the error, my package installed and imported fine in some contexts but not others
Solution 2:[2]
I was able to solve for this by moving my featurestore
directory up one level, and getting rid of the src
directory. Based on the top answer here, I may have been able to also solve for it by simply adding a __init__.py
file directly in the src
directory. But for my need, src
was really an unnecessary level.
New package directory set-up:
Code ran in terminal:
!pip3 install -U git+ssh://git@dsghe.<mydomain>/bshelton/package_test.git@master#egg=featurestore
from featurestore.featurestore import *
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bede Constantinides |
Solution 2 | bshelt141 |