【问题标题】:`ModuleNotFoundError` When Importing Python Package from Git从 Git 导入 Python 包时出现“ModuleNotFoundError”
【发布时间】:2021-07-29 16:54:25
【问题描述】:

我正在尝试使用以下命令通过 ssh 从私有 GitHub 存储库安装 featurestore 包:

pip3 install -U git+ssh://git@dsghe.<mydomain>/bshelton/package_test.git@master#egg=featurestore

安装成功,如下图所示:

但是在尝试运行 from featurestore import * 时,我收到了 ModuleNotFoundError: No module named 'featurestore' 错误。

使用pip3 freeze,我看到包已安装,但没有使用我期望的&lt;package&gt;==&lt;version&gt; 语法,但它似乎将git commit 引用为其“版本”:

根据下面的屏幕截图,我认为 repo 的目录设置适合 Python 包。

这个包的安装和我安装的其他包之间的一个显着区别是,我的...dist-info 包似乎只安装了featurestore 文件夹,而所有其他安装的包都包含实际的包目录,在除了...dist-info 文件夹。使用ls ~/.local/lib/python3.6/site-packages

这是我第一次尝试创建这样的包,并且我一直在参考以下几个来源,但希望社区能提供一些关于我所缺少的内容的见解。谢谢。

https://packaging.python.org/tutorials/packaging-projects/

pip install from git repo branch

【问题讨论】:

标签: python python-3.x package


【解决方案1】:

我可以通过将featurestore 目录上移一级并删除src 目录来解决这个问题。基于最佳答案here,我可能也可以通过直接在src 目录中添加__init__.py 文件来解决它。但是对于我的需要,src 确实是一个不必要的级别。


新的包目录设置:


代码在终端中运行:

!pip3 install -U git+ssh://git@dsghe.<mydomain>/bshelton/package_test.git@master#egg=featurestore
from featurestore.featurestore import *

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 1970-01-01
    • 2019-07-03
    • 2021-09-03
    • 2021-07-12
    • 2021-01-26
    • 1970-01-01
    • 2021-05-10
    • 2021-05-09
    相关资源
    最近更新 更多