最近因为一些工作上的项目需要跑Vispy用于绘图,结果官方给的示例怎么也跑不通,每次都是
... WARNING: Traceback (most recent call last):
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\app\backends\_qt.py", line 436, in event
out = super(QtBaseCanvasBackend, self).event(ev)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\app\backends\_qt.py", line 708, in paintGL
self._vispy_canvas.events.draw(region=None)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\event.py", line 455, in __call__
self._invoke_callback(cb, event)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\event.py", line 475, in _invoke_callback
self, cb_event=(cb, event))
<< caught exception here: >>
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fetching.py", line 245, in _fetch_file
file_size = int(data.headers['Content-Length'].strip())
AttributeError: 'NoneType' object has no attribute 'strip'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\event.py", line 471, in _invoke_callback
cb(event)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\scene\canvas.py", line 207, in on_draw
self._draw_scene()
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\scene\canvas.py", line 253, in _draw_scene
self.draw_visual(self.scene)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\scene\canvas.py", line 291, in draw_visual
node.draw()
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\scene\visuals.py", line 98, in draw
self._visual_superclass.draw(self)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\visual.py", line 588, in draw
v.draw()
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\visual.py", line 432, in draw
if self._prepare_draw(view=self) is False:
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\text\text.py", line 446, in _prepare_draw
self._font._lowres_size) for t in text])
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\text\text.py", line 446, in <listcomp>
self._font._lowres_size) for t in text])
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\text\text.py", line 157, in _text_to_vbo
glyph = font[char]
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\text\text.py", line 69, in __getitem__
self._load_char(char)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\visuals\text\text.py", line 83, in _load_char
_load_glyph(self._font, char, self._glyphs)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fonts\_freetype.py", line 50, in _load_glyph
face = _load_font(f['face'], f['bold'], f['italic'])
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fonts\_freetype.py", line 34, in _load_font
fname = _get_vispy_font_filename(face, bold, italic)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fonts\_vispy_fonts.py", line 20, in _get_vispy_font_filename
return load_data_file('fonts/%s' % name)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fetching.py", line 68, in load_data_file
_fetch_file(url, fname)
File "C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fetching.py", line 257, in _fetch_file
'Dataset fetching aborted (%s)' % (url, e))
RuntimeError: Error while fetching file http://github.com/vispy/demo-data/tree/main/fonts/OpenSans-Regular.ttf.
似乎是链接问题,根据提示定位了一下代码发现关键是C:\Users\A\anaconda3\envs\torch17\lib\site-packages\vispy\util\fetching.py这个文件定义了下载链接:
def load_data_file(fname, directory=None, force_download=False):
"""Get a standard vispy demo data file
Parameters
----------
fname : str
The filename on the remote ``demo-data`` repository to download,
e.g. ``'molecular_viewer/micelle.npy'``. These correspond to paths
on ``https://github.com/vispy/demo-data/``.
directory : str | None
Directory to use to save the file. By default, the vispy
configuration directory is used.
force_download : bool | str
If True, the file will be downloaded even if a local copy exists
(and this copy will be overwritten). Can also be a YYYY-MM-DD date
to ensure a file is up-to-date (modified date of a file on disk,
if present, is checked).
Returns
-------
fname : str
The path to the file on the local system.
"""
_url_root = 'http://github.com/vispy/demo-data/raw/master/'
url = _url_root + fname
if directory is None:
directory = config['data_path']
if directory is None:
raise ValueError('config["data_path"] is not defined, '
'so directory must be supplied')
fname = op.join(directory, op.normcase(fname)) # convert to native
if op.isfile(fname):
if not force_download: # we're done
return fname
if isinstance(force_download, string_types):
ntime = time.strptime(force_download, '%Y-%m-%d')
ftime = time.gmtime(op.getctime(fname))
if ftime >= ntime:
return fname
else:
print('File older than %s, updating...' % force_download)
if not op.isdir(op.dirname(fname)):
os.makedirs(op.abspath(op.dirname(fname)))
# let's go get the file
_fetch_file(url, fname)
return fname
我尝试打开’http://github.com/vispy/demo-data/tree/main/fonts/OpenSans-Regular.ttf’发现确实不存在,到网上搜索发现了这个,这里提到了另外的url:‘https://github.com/vispy/demo-data/tree/main/fonts’,参考之下把_url_root改成了’‘https://github.com/vispy/demo-data/raw/main/’',之后就可以正常下载了。
问题不复杂,但是还挺有帮助,国内Vispy相关教程少,特此记录。