Python 由于PySide2和Matplotlib,Travis CI无法生成
我有一个github存储库,在那里我开发了一个 最近我完全从PyQt5迁移到PySide2 今天,我添加了用于持续集成的Travis CI作为Githb存储库的挂钩。这意味着,当我推动一些更改时,travis CI会在云计算中的一台独立机器上启动我的存储库构建 Travis CI因以下原因而失败:Python 由于PySide2和Matplotlib,Travis CI无法生成,python,matplotlib,python-3.6,travis-ci,pyside2,Python,Matplotlib,Python 3.6,Travis Ci,Pyside2,我有一个github存储库,在那里我开发了一个 最近我完全从PyQt5迁移到PySide2 今天,我添加了用于持续集成的Travis CI作为Githb存储库的挂钩。这意味着,当我推动一些更改时,travis CI会在云计算中的一台独立机器上启动我的存储库构建 Travis CI因以下原因而失败: ImportError while importing test module '/home/travis/build/SanPen/GridCal/src/tests/test_branch_tol
ImportError while importing test module '/home/travis/build/SanPen/GridCal/src/tests/test_branch_tolerance.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: src/tests/test_branch_tolerance.py:1: in <module>
from GridCal.Engine import * src/GridCal/Engine/__init__.py:17: in <module>
from GridCal.Engine.basic_structures import * src/GridCal/Engine/basic_structures.py:23: in <module>
from GridCal.Engine.plot_config import LINEWIDTH, plt src/GridCal/Engine/plot_config.py:18: in <module>
matplotlib.use('Qt5Agg') ../../../virtualenv/python3.6.7/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py:307: in wrapper
return func(*args, **kwargs) ../../../virtualenv/python3.6.7/lib/python3.6/site-packages/matplotlib/__init__.py:1297: in use
switch_backend(name) ../../../virtualenv/python3.6.7/lib/python3.6/site-packages/matplotlib/pyplot.py:230: in switch_backend
newbackend, required_framework, current_framework))
E ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework, as 'headless' is currently running
这段代码是我在几个线程上发现的正确做法。然而,独立机器上的自动测试也因此而失败
那么,告诉matplotlib使用PySide2的最佳且明确的方法是什么?
所需的软件包是(requirements.txt):
必须按照中的指示启用XVFB服务,才能测试需要图形环境的库:
dist: xenial # required for Python >= 3.7
services:
- xvfb
language: python
python:
- "3.6"
- "3.7"
# command to install dependencies
install:
- pip install -r requirements.txt
# command to run tests
script:
- pytest
我已为您的存储库创建了一个链接。您使用pyplot的目的是什么?该项目看起来像是完全将matplotlib嵌入PySide GUI?
plt
用于文件中设置默认样式。关注后端的东西。是的,所以错误只是因为你导入了pyplot,这似乎是不必要的。您也不需要pyplot来设置任何默认样式。所以这里实际上有两个不同的东西,一个是让您的repo运行,另一个是如何设置后端在使用pyplot时使用pyside2。文件就是我说的,删除行matplotlib.use
。我的观点是,您不想设置任何意义上的后端。请使用。这仅适用于pyplot,但使用pyplot与在自定义GUI中嵌入matplotlib相矛盾。这样不仅可以防止这些测试失败,还可以防止在启动软件之前的任何时候已经设置了不同后端的用户出现问题。
PySide2>=5.11
numpy>=1.14.0
scipy>=1.0.0
networkx>=2.1
pandas>=0.22
xlwt>=1.3.0
xlrd>=1.1.0
matplotlib>=3.1.0
qtconsole>=4.3.1
pyDOE>=0.3.8
pySOT>=0.2.1
openpyxl>=2.4.9
pulp>=1.6.8
smopy>=0.0.6
chardet>=3.0.4
scikit-learn>=0.18
geopy>=1.16
pytest>=3.8
h5py>=2.9.0
dist: xenial # required for Python >= 3.7
services:
- xvfb
language: python
python:
- "3.6"
- "3.7"
# command to install dependencies
install:
- pip install -r requirements.txt
# command to run tests
script:
- pytest