Can't find my python module after installing on Github Actions

你离开我真会死。 提交于 2021-02-11 07:00:15

问题


When I install my example module in the local environment, python is able to find it when the module is imported. Whereas, when executed by Github Actions, the workflow fails and the reported error is that my module (ci-test) is not installed.

main.yaml:

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

The full yaml file is located here. And the error output of Github Actions is:

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.

回答1:


The issue is not related to github action.

When looking to your repository, the repository is organized this way.

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

And in your setup.py you describe your packages as:

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

Your ci_test package can be import with the following path: import src.ci_test

This question have some best practices about python project structure: What is the best project structure for a Python application?



来源:https://stackoverflow.com/questions/65014768/cant-find-my-python-module-after-installing-on-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!