In my code
from pygame.locals import *
gets the following error message:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from pygame.locals import *
ImportError: No module named 'pygame.locals'
I have ensured that I don't have any files named pygame.py or pygame.pyc in my working directory and I'm using Python3.3.5 and pygame-1.9.2a0-hg on Windows 10. Could there be any other reason for this error?
Using Pycharm. My python file was called pygame. When I copied and pasted the code into another python file with a different name, it worked. This is as new to me as anything.
Related
I have pygame and numpy in the same folder. I can import pygame, but I can only import numpy in the terminal, not even in the IDLE. If I try to import numpy anywhere else, I get this message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
I can also still import pygame into the terminal. Also, python in the terminal is version 3.7.5, but in the IDLE it's 3.6.6. Not sure if that's related.
All of my modules are in the default path folder.
I've installed igraph form .whl file using pip install. When I was trying to test the correctness of installation
import igraph.test
igraph.test.test()
I got this error:
Traceback (most recent call last):
File "D:/Nauka/Praca-inzynierska/Barabasi-Albert.py", line 4, in <module>
import igraph.test
File "D:\Programy\Python 3.5\lib\site-packages\igraph\__init__.py", line 34, in <module>
from igraph._igraph import *
ImportError: No module named 'igraph._igraph'
(the same error pops out if I'm trying to import igraph not igraph.test).
I've tried adding path (I don't know if this is rigth):
import sys
sys.path.append ("D:/Programy/Python 3.5/Lib/site-packages/igraph")
but it didn't work.
One thing I discovered is that if I delete "__init__" file from igraph folder I can import igraph without error, but it doesn't work for igraph.test.
If it's relevant I have Python 2.7 installed on my machine alongside Python 3.5.
Thank you in advance for any help.
I need a glut window in python.
I have the following exception using Python 3.5 and PyOpenGL.GLUT
Traceback (most recent call last):
File "D:\...\Test.py", line 47, in <module>
if __name__ == '__main__': main()
File "D:\...\Test.py", line 9, in main
glutInit(sys.argv)
File "C:\...\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "C:\...\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit,
check for bool(glutInit) before calling
Platform: Windows
Why do i get this error?
Here is my code:
from OpenGL.GLUT import *
import sys
glutInit(sys.argv)
Problems:
There was no problem with pip install or easy_install
The glut.dll and glut32.dll were missing. (They are not part of the PyPI package) you have to install them separately or download it like I did.
Unzipped the dll files from the glutdlls.zip and placed them next to my python file.
Note: You can add the dll files to your PATH variable. Not necessary to keep them next to the py file.
I was being thrown the same error message. I tried installing the DLLs separately and everything and nothing worked.
The code that gave me the error was calling the glutInit() function. While I was getting the error, my imports looked like:
import OpenGL
import OpenGL.GL
import OpenGL.GLUT
import OpenGL.GLU
I then changed my imports to:
import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
and the error was fixed.
I can use the module correctly by Python, but when using Jython, some error occurs...
Code:
from jieba import *
Errors:
Traceback (most recent call last):
File "/Users/Jack/Documents/workspace/FirstJython/hellojyphon.py", line 8, in <module>
from jieba import *
File "/Users/Jack/Documents/workspace/FirstJython/jieba/__init__.py", line 15, in <module>
from ._compat import *
ImportError: No module named _compat
Is there any differences between Python and Jython when import?
I solve it by myself.
There is something wrong when using relative directories in Jython.
so after I change ._compat to jieba._compat, the problem solved!
But I don't exactly know the reason...
I am using a mac and i want to use pygame but it is not working.
this is the error i get when I try to do import pygame
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
Please help I am using python 2.7.9
If your file name is called pygame.py the system imports your python file.
If your file name is not pygame.py, you can try doing pip install pygame or python -m install pygame.