应用程序在本地运行,在 PyPi 中使用 ModuleNotFound 失败

App runs locally, fails in PyPi with ModuleNotFound

我将下面的 src/sample/run.py 添加到 sampleproject。它在本地运行(打印“add_one(2) = 3”),但部署的 pip 版本失败:

virtualenv venv
source venv/bin/activate
pip install -i https://test.pypi.org/simple/ sampleproject-valhuber
sample-run
ModuleNotFoundError: No module named 'simple'

这里是src/sample/run.py:

import simple  # FAILS in PyPi: ModuleNotFoundError...
def main():
    print("add_one(2) = " + str(simple.add_one(2)))
if __name__ == '__main__':
    main()

完整代码以及打包过程在this GitHub project.

您的 simple.pysample 包裹内。您必须从包中导入它:

import sample.simple

from sample import simple