Search code examples
pythonimportmodulepyglet

No module named pyglet


I'm having a strange issue with pyglet. After running pip install pyglet and restarting my command line application, I'm still unable to run a python script that imports pyglet.

Error output:

$ python main.py
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    from pyglet import image
ImportError: No module named pyglet

Running pip install pyglet again gives:

pip install pyglet
--> Requirement already satisfied (use --upgrade to upgrade): 
    pyglet in c:\python34\lib\site-packages

This is on a Windows 7 machine running Python 2.7, and the script in question can be found here: https://github.com/fogleman/Minecraft/blob/master/main.py

What's the matter with pyglet?


Solution

  • This line

    pyglet in c:\python34\lib\site-packages
                       ^    
    

    means that you installed module for python 3.4. You need to install it for 2.7 instead:

    python2.7 -m pip install pyglet
    

    or, which is more reliable in your case

    python -m pip install pyglet