在GithubActions上安装后找不到我的python模块

当我在本地环境中安装我的示例模块时,python 能够在导入模块时找到它。然而,当由 Github Actions 执行时,工作流失败并且报告的错误是我的模块 (ci-test) 未安装。

main.yaml:

  - name: Install ci-test package
    run: |
      python setup.py build
      python setup.py install 
      python -c "import ci_test"

完整的 yaml 文件位于此处。Github Actions 的错误输出是:

Installed /home/runner/.local/lib/python3.7/site-packages/ci_test-0.0.1-py3.7.egg
Processing dependencies for ci-test==0.0.1
Finished processing dependencies for ci-test==0.0.1
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ci_test'
Error: Process completed with exit code 1.

回答

该问题与 github 操作无关。

在查看您的存储库时,存储库的组织方式是这样的。

ci-test/
|-- requirements.txt
|-- setup.py
|-- src/
|   |-- ci_test/
|   |   |-- app.py
|   |   |-- __init__.py
|   |   |-- main.py
|-- tests/
|   |-- app_test.py
|   |-- __init__.py
|   |-- main_test.py

并在您的setup.py描述中将您的包裹描述为:

packages=['src/ci_test', 'tests']

ci_test可以使用以下路径导入您的包:import src.ci_test

这个问题有一些关于 Python 项目结构的最佳实践:Python 应用程序的最佳项目结构是什么?


以上是在GithubActions上安装后找不到我的python模块的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>