8

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.
Emanuel Huber
  • 131
  • 2
  • 12

2 Answers2

6

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?

chapipo
  • 101
  • 5
  • You are right chapipo, the error was with my project structure. I wasn't able to make the test module separated from the main package, I solved this by including the tests package inside the main module, and now it works perfectly. Thank you for your help, you gave me a good direction, I will rephrase the question with your input. – Emanuel Huber Nov 29 '20 at 23:10
1

sorry for digging up, but i can't find any other related question:

if after installing running:

pip3 install --user -r requirements.txt

you still get an exception: ModuleNotFoundError: No module named for external libraries (in my case it was jsonrpcserver) even it's exists in requirements.txt and you directly install it with pip3 install command, try theese:

  • remove pre-defined by github actions way of installing python, from this:
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

to this: sudo apt-get install python3

  • try to remove --user flag from pip install command