Module Not Found Error For Custom Pypi Package

huangapple go评论64阅读模式
英文:

Module Not Found Error For Custom Pypi Package

问题

我试图将我的包上传到pypi并使用它。使用Twine上传到pypi后,当我尝试使用这个包时,我收到了"模块未找到"的错误。

我的错误:
Module Not Found Error For Custom Pypi Package

我包的文件结构如下:
Module Not Found Error For Custom Pypi Package

错误指向modelpg/__init__.py,以下是我的modelpg/__init__.py文件:
Module Not Found Error For Custom Pypi Package

是否是因为我的包名与.py文件同名。

编辑 1:
我的Transformer/__init__.py文件:
Module Not Found Error For Custom Pypi Package

英文:

I am trying to upload my package to pypi and use it. Using Twine i upload it to pypi but when i try to use this package I get Module not found error.
<br>My Error :
Module Not Found Error For Custom Pypi Package

My Folder structure for the package is : <br>
Module Not Found Error For Custom Pypi Package

The error points to the modelpg/__init__.py , here's my modelpg/__init__.py file. <br>

Module Not Found Error For Custom Pypi Package

Is it due to my package name is same as .py file.

EDIT 1 :
My Transformer/__init__.py file <br>
Module Not Found Error For Custom Pypi Package

答案1

得分: 1

modelpg/__init__.py 中的所有导入需要是相对的:

from .Transformer.transformer import Transformer

或者是绝对的,使用 modelpg 包名:

from modelpg.Transformer.transformer import Transformer

这与 PyPI 无关,顺便说一句 - 即使包没有从那里安装也适用。

英文:

All of the imports in modelpg/__init__.py would need to either be relative:

from .Transformer.transformer import Transformer

or absolute, with the modelpg package name:

from modelpg.Transformer.transformer import Transformer

This has nothing to do with PyPI, by the way – the same applies even if the package wasn't installed from there.

huangapple
  • 本文由 发表于 2023年2月10日 13:18:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407241.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定