Attempt to call an undefined function glutInit - python

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.

Related

Why isn't pyinstaller making a Tkinter window?

It's important to know that I am using pyinstaller to package python.
tkinter works perfectly fine when I package it with only:
import tkinter
root=tkinter.Tk()
root.mainloop()
but when I add some more of my code it shows the error:
Traceback (most recent call last):
File "exec", line 1, in <module>
import tkinter
File "C:\Program Files\Python38\lib\tkinter\__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: Module use of python39.dll conflicts with this version of Python.
These are all my imports:
import discord
import subprocess
from os import getcwd
import os
import pyautogui
from threading import *
import sys
I tried using only a tkinter window with no extra code and that worked!
But when I add the rest of my code it shows the error:
Traceback (most recent call last):
File "exec", line 1, in \<module\>
import tkinter
File "C:\\Program Files\\Python38\\lib\\tkinter\__init_\_.py", line 36, in \<module\>
import \_tkinter # If this fails your Python may not be configured for Tk
ImportError: Module use of python39.dll conflicts with this version of Python.

mathplotlib six.moves.urllib.request import error

I just had this problem while trying to import mathplotlib.
This was the error I was getting:
Traceback (most recent call last):
File "C:/xxx/solver.py", line 7, in <module>
import matplotlib
File "C:\Users\xxx\Anaconda2\lib\site-packages\matplotlib\__init__.py", line 129, in <module>
from six.moves.urllib.request import urlopen
ImportError: cannot import name urlopen
Here is the solution I used to fix this issue. It took me a while to figure this out and I couldn't find any references online that helped me, so I am posting the solution here.
I replaced the offending line in matplotlib/init.py
from six.moves.urllib.request import urlopen
with:
from urllib.request import urlopen
which allowed me to see the real error:
import socket
File "C:\PROJECTS\xxx\socket.py", line 7, in <module>
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'AF_INET'
So the problem was that I had named one of my modules "socket.py" and this was causing an error, which was masked by the six.moves importing mechanism. This file was stacked fairly deep in my project tree, but it happened to be at the same level as the script I was trying to run, which is presumably why it was being imported at the root level.
I was using PyCharm on windows for all of this.

Unintentionally finding two different files with the same python interpreter and system path

I'm trying to run the Spyder IDE but it fails because it imports the wrong file. I get an ImportError attempting to run it from the command line:
$ /opt/anaconda3/bin/spyder
Traceback (most recent call last):
File "/opt/anaconda3/bin/spyder", line 6, in <module>
sys.exit(spyder.app.start.main())
File "/opt/anaconda3/lib/python3.5/site-packages/spyder/app/start.py",
line 103, in main
from spyder.app import mainwindow
File "/opt/anaconda3/lib/python3.5/site-packages/spyder/app/mainwindow.py",
line 78, in <module>
from qtpy.compat import from_qvariant
File "/opt/anaconda3/lib/python3.5/site-packages/qtpy/compat.py",
line 15, in <module>
from qtpy.QtWidgets import QFileDialog
File "/opt/anaconda3/lib/python3.5/site-packages/qtpy/QtWidgets.py",
line 27, in <module>
from PyQt5.QtWidgets import *
ImportError: /opt/anaconda3/lib/python3.5/site-packages/PyQt5/Qt/lib/libQt5Gui.so.5:
symbol _Z10qAllocMoreii, version Qt_5 not defined in file libQt5Core.so.5 with
link time reference
However, when I run from the python interpreter at /opt/anaconda3/bin/python the command from PyQt5.QtWidgets import *, it works fine. Ok, so naturally I think this is a sys.path issue. So I modify /opt/anaconda3/lib/python3.5/site-packages/qtpy/QtWidgets.py to print out the system path and system executable. The relevant segment of code is:
print(sys.path)
print(sys.executable)
from PyQt5.QtWidgets import *
Which prints the result:
['/opt/anaconda3/bin', '/opt/anaconda3/lib/python35.zip',
'/opt/anaconda3/lib/python3.5',
'/opt/anaconda3/lib/python3.5/plat-linux',
'/opt/anaconda3/lib/python3.5/lib-dynload',
'/opt/anaconda3/lib/python3.5/site-packages',
'/opt/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg',
'/opt/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
/opt/anaconda3/bin/python
The result from the interpreter for the same two commands is:
['', '/opt/anaconda3/lib/python35.zip',
'/opt/anaconda3/lib/python3.5',
'/opt/anaconda3/lib/python3.5/plat-linux',
'/opt/anaconda3/lib/python3.5/lib-dynload',
'/opt/anaconda3/lib/python3.5/site-packages',
'/opt/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg',
'/opt/anaconda3/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg']
/opt/anaconda3/bin/python
So the paths are exactly the same except for the first directory, but that is irrelevant because the interpreter finds the appropriate library in the right directory:
$ /opt/anaconda3/bin/python
>>> import PyQt5.QtWidgets
>>> print(PyQt5.QtWidgets)
<module 'PyQt5.QtWidgets' from
'/opt/anaconda3/lib/python3.5/site-packages/PyQt5/QtWidgets.so'>
So in summary, even though I'm using the same interpreter with the same system path, I find two different files in two different locations with the same import command. How is that possible? How do I prevent it doing whatever it is doing?

Python igraph import error on Windows

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.

pygame: from pygame.locals import * not working

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.

Categories

Resources