Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 564
Emanuel Huber Avatar asked Mar 01 '23 21:03

Emanuel Huber


1 Answers

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?

like image 190
chapipo Avatar answered Mar 05 '23 15:03

chapipo