简体   繁体   中英

Import Errror for python pg module

I am having trouble using the pg module in my code. I've installed it using pip. But when I go to run it I get the following error:

Traceback (most recent call last):
  File "Contract_gen.py", line 2, in <module>
    import pg
  File "C:\Python27\lib\site-packages\pg\__init__.py", line 1, in <module>
    from .core import (
  File "C:\Python27\lib\site-packages\pg\core.py", line 6, in <module> 
    from . import glfw
  File "C:\Python27\lib\site-packages\pg\glfw.py", line 140, in <module>
    raise ImportError("Failed to load GLFW3 shared library.")
ImportError: Failed to load GLFW3 shared library.

It seems like to require the GLFW3 library. Download & install it and the error should be gone. If you use macOS you can get it via brew .

Your version of OpenGL might be too old compared to the pg requirement which is 3.1.0 as specified in https://github.com/fogleman/pg/blob/master/requirements.txt

You can re install python-openGL with pip:

$ pip install PyOpenGL PyOpenGL_accelerate

This removes this problem but creates other errors for me.

note, besides, that this problem seems to be mentioned in https://github.com/fogleman/pg/issues

How to solve for windows:

  1. Download Windows pre-compiled binaries from https://www.glfw.org/download.html
  2. copy (and replace) the file lib-mingw-w64\\glfw3.dll to ...\\Python27\\Lib\\site-packages\\glfw\\glfw3.dll
  3. Done

For me, glfw was working fine until one morning when it suddenly wasn't. This solution worked for me. I don't know if this is the correct way to solve it but it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM