如何让 p5在 Python 中处理显示在 Google Colab 中?

问题描述

一个 new p5 library in pyPI 可以安装在 Google Colaboratory 中:

!pip install -U p5
import p5

但是,我在显示图表时遇到了问题。 glfw 似乎有问题 - 让它将图形发送到正确的显示器。我在Win10上使用这个。 阅读文档以及 p5 的安装说明是 here

以下示例取自 p5 存储库 - https://github.com/p5py/p5

def setup():
    p5.size(640,360)
    p5.no_stroke()
    p5.background(204)

def draw():
    if p5.mouse_is_pressed:
        p5.fill(p5.random_uniform(255),p5.random_uniform(127),p5.random_uniform(51),127)
    else:
        p5.fill(255,15)

    circle_size = p5.random_uniform(low=10,high=80)

    p5.circle((p5.mouse_x,p5.mouse_y),circle_size)

def key_pressed(event):
    p5.background(204)

p5.run()

错误信息是:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-7-2146d31dac46> in <module>()
     20     p5.background(204)
     21 
---> 22 p5.run()

5 frames
/usr/local/lib/python3.7/dist-packages/vispy/app/backends/_glfw.py in _vispy_get_native_app(self)
    213             try:
    214                 if not glfw.glfwInit():  # only ever call once
--> 215                     raise OSError('Could not init glfw:\n%r' % _glfw_errors)
    216             finally:
    217                 os.chdir(cwd)

OSError: Could not init glfw:
["Error 65544: b'X11: The disPLAY environment variable is missing'"]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)