Tutorial to add pyqt5
to GitHub can be here in this thread:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.6
architecture: x64
- name: Install pyqt4 pyqt5
run: |
sudo apt-get install python3-setuptools python3-pyqt5 python3-pyqt4
python3 -m pip install matplotlib
- name: create testqt5.py
run: |
cat <<EOF >testqt5.py
import matplotlib
matplotlib.use('Qt5Agg')
from PyQt5 import QtCore, QtWidgets
EOF
- name: Run python script
run: |
python3 testqt5.py
env:
PYTHONPATH: ":/usr/lib/python3/dist-packages"
- name: create testqt4.py
run: |
cat <<EOF >testqt4.py
import matplotlib
matplotlib.use('Qt4Agg')
from PyQt4 import QtCore, QtGui
EOF
- name: Run python script
run: |
python3 testqt4.py
env:
PYTHONPATH: ":/usr/lib/python3/dist-packages"
But, it didn't use matrix.python-version
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
How to setup GitHub action that support matplotlib.use('Qt5Agg')
using matrix.python-version
?
import matplotlib
matplotlib.use('Qt5Agg')
It would be better if solution also support Windows and MAC using matrix.os
Here is my attempt and the error message:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install pyqt5
run: |
sudo apt-get install python3-pyqt5
- name: Test
run: |
pip install pytest pytest-cov
pytest
env:
PYTHONPATH: ":/usr/lib/python3/dist-packages"
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.6.15/x64/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 25, in <module>
from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
File "/usr/lib/python3/dist-packages/pip/_internal/locations.py", line 19, in <module>
from pip._internal.utils import appdirs
File "/usr/lib/python3/dist-packages/pip/_internal/utils/appdirs.py", line 13, in <module>
from pip._vendor import appdirs as _appdirs
ImportError: cannot import name 'appdirs'
Worked example without any matrix:
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Clone this repository
uses: actions/checkout@v3
- name: Install pyqt4 pyqt5
run: |
sudo apt-get install python3-setuptools python3-pyqt5
python3 -m pip install matplotlib
- name: Run python script
run: |
python3 test_matplotlib_pyqt5.py
See my progress trying implementing this on my GitHub
EDIT
Solved by avoiding:
- PYTHONPATH
- Python<=3.6
- PyQt4
CodePudding user response:
It seems that the problem is a combination of using PYTHONPATH
, Python<=3.6
, and PyQt4
.
Thus, the minimal working example of the build is:
name: CI-python-matrix
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- name: Clone this repository
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install pyqt5
run: |
sudo apt-get update
sudo apt-get install python3-setuptools python3-pyqt5
python3 -m pip install matplotlib PyQt5
- name: Run python script
run: |
python3 test_matplotlib_pyqt5.py
See my journey on solving this problem in my GitHub repository commit history
EDIT
Interestingly, if only using Python>=3.7, we can skip sudo operation and rely sololy on pip.
name: CI-python-os-matrix
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Clone this repository
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install with cache
run: |
pip install -r requirements.txt
- name: Run python script
run: |
python3 test_matplotlib_pyqt5.py