I am using OpenGL to render a scene in python. My code works perfectly fine on windows but, for some reason, I'm having issues when importing opengl.gl on MacOS.
The issue arises when calling from OpenGL.GL import ... in both python scripts and the python console.
More specifically here is the exact call in my script:
from OpenGL.GL import glGenBuffers, glBindBuffer, glBufferData, \
glGenVertexArrays, glBindVertexArray, glEnableVertexAttribArray, glVertexAttribPointer, \
glDrawArrays, glUseProgram, glEnable, glDisable, \
GL_ARRAY_BUFFER, GL_STATIC_DRAW, GL_DEPTH_TEST, \
GL_FLOAT, GL_FALSE, \
GL_TRIANGLES, GL_LINES, GL_LINE_STRIP
This results in the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 35, in GL
return ctypesloader.loadLibrary(
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/ctypesloader.py", line 36, in loadLibrary
return _loadLibraryWindows(dllType, name, mode)
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/ctypesloader.py", line 89, in _loadLibraryWindows
return dllType( name, mode )
File "/usr/local/Cellar/python#3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ('dlopen(OpenGL, 10): image not found', 'OpenGL', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/iyadboustany/Desktop/lensmaster/Lensmaster.py", line 18, in <module>
from MainWindow import MainWindow
File "/Users/iyadboustany/Desktop/lensmaster/MainWindow.py", line 14, in <module>
from Robot import Robot
File "/Users/iyadboustany/Desktop/lensmaster/Robot.py", line 8, in <module>
from Graphics.Scene import DHNode
File "/Users/iyadboustany/Desktop/lensmaster/Graphics/Scene.py", line 13, in <module>
from OpenGL.GL import glGenBuffers, glBindBuffer, glBufferData, \
File "/usr/local/lib/python3.8/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
from OpenGL import error as _error
File "/usr/local/lib/python3.8/site-packages/OpenGL/error.py", line 12, in <module>
from OpenGL import platform, _configflags
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/__init__.py", line 36, in <module>
_load()
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/__init__.py", line 33, in _load
plugin.install(globals())
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 97, in install
namespace[ name ] = getattr(self,name,None)
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 62, in GetCurrentContext
return self.CGL.CGLGetCurrentContext
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 45, in CGL
def CGL(self): return self.GL
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 41, in GL
raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', 'dlopen(OpenGL, 10): image not found', 'OpenGL', None)
Notes:
Running glxgears works just fine.
I'm running macOS Big Sur beta (20A5343i)
I'm using python 3.8.5
I installed opengl using pip: pip3 install PyOpenGL PyOpenGL_accelerate
This error is because Big Sur no longer has the OpenGL library nor other system libraries in standard locations in the file system and instead uses a cache. PyOpenGL uses ctypes to try to locate the OpenGL library and it fails to find it. Fixing ctypes in Python so that it will find the library is the subject of this pull request
https://github.com/python/cpython/pull/21241
So a future version of Python should resolve the problem.
To fix it now you can edit PyOpenGL file OpenGL/platform/ctypesloader.py changing line
fullName = util.find_library( name )
to
fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'
Since I hate the idea of patching a Python package (plus it is really hard to manage that with use of Conda to install said package), I offer this kludge as a workaround for until Python gets its Big Sur (aka Big Nuisance) update:
try:
import OpenGL as ogl
try:
import OpenGL.GL # this fails in <=2020 versions of Python on OS X 11.x
except ImportError:
print('Drat, patching for Big Sur')
from ctypes import util
orig_util_find_library = util.find_library
def new_util_find_library( name ):
res = orig_util_find_library( name )
if res: return res
return '/System/Library/Frameworks/'+name+'.framework/'+name
util.find_library = new_util_find_library
except ImportError:
pass
It's better to change this to
fullName = "/System/Library/Frameworks/{}.framework/{}".format(name,name)
otherwise GLUT won't work. At least, this let me run the Cozmo SDK's 3d stuff again.
FYI, in my case it was:
fullName = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/OpenGL'
None of these are really very suitable answers - there were several issues with both MacOS and pyOpenGL.
Fortunately, however - everything seems to be working at last if we upgrade to Python3.10 (or above)
Related
I am using the pyattck module to retrieve information from mitre att&ck.
Versions:
- pyattck==7.0.0
- pyattck-data==2.5.2
Then, I just created a simple main.py file to test the module.
from pyattck import Attck
def main():
attck = Attck()
for technique in attck.enterprise.techniques:
print(technique.name)
if __name__ == '__main__':
main()
When running the main.py script I get the following exception:
Traceback (most recent call last):
File "/<path>/main.py", line 15, in <module>
main()
File "/<path>/main.py", line 8, in main
for technique in attck.enterprise.techniques:
File "/<path_venv>/lib/python3.10/site-packages/pyattck/attck.py", line 253, in enterprise
from .enterprise import EnterpriseAttck
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 7, in <module>
class EnterpriseAttck(Base):
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 42, in EnterpriseAttck
__attck = MitreAttck(**Base.config.get_data("enterprise_attck_json"))
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 55, in __init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 53, in __init__
self.__attrs_init__(**kwargs)
File "<attrs generated init pyattck_data.attack.MitreAttck>", line 14, in __attrs_init__
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 66, in __attrs_post_init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 62, in __attrs_post_init__
data = TYPE_MAP.get(item['type'])(**item)
TypeError: 'NoneType' object is not callable
Anyone knows where is the issue? Maybe I have forgotten to import something? It would be helpful to know if this module actually works in another version. This one is the lasted stable one ATTOW.
UPDATE
There is am issue with this project. Mitre added some new features that are not supported by the module and make it unusable.
There is an issue on github related to this.
They have already fixed this issue in future releases. You just need to update your package pyattck-data form the bugged version 2.5.2 to 2.6.1 (or any newer).
If you are using pip, just run this:
pip install --upgrade pyattck-data
If you are using conda (inside your venv):
conda update pyattck-data
I am trying the following code:
import gym
env = gym.make('ma_gym:Switch2-v0')
done_n = [False for _ in range(env.n_agents)]
ep_reward = 0
obs_n = env.reset()
while not all(done_n):
env.render()
obs_n, reward_n, done_n, info = env.step(env.action_space.sample())
ep_reward += sum(reward_n)
env.close()
However, when I run it, I get the following error messages:
Advay#advays-mbp evolution-org-main % /Users/Advay/miniforge3/envs/evolution_env/bin/python "/Users/Advay/Library/Mobile Documents/com~apple~CloudDocs/Brown/Research/Rose Lab/evolution-org-main/magym-room-v0/runner.py"
/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/logger.py:34: UserWarning: WARN: Box bound precision lowered by casting to float32
warnings.warn(colorize("%s: %s" % ("WARN", msg % args), "yellow"))
Traceback (most recent call last):
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py", line 27, in <module>
from pyglet.gl import *
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/__init__.py", line 95, in <module>
from pyglet.gl.lib import GLException
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/lib.py", line 147, in <module>
from pyglet.gl.lib_agl import link_GL, link_GLU, link_AGL
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/lib_agl.py", line 43, in <module>
gl_lib = pyglet.lib.load_library(framework='/System/Library/Frameworks/OpenGL.framework')
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/lib.py", line 124, in load_library
return self.load_framework(kwargs['framework'])
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/lib.py", line 279, in load_framework
raise ImportError("Can't find framework %s." % path)
ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Advay/Library/Mobile Documents/com~apple~CloudDocs/Brown/Research/Rose Lab/evolution-org-main/magym-room-v0/runner.py", line 9, in <module>
env.render()
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/ma_gym/envs/switch/switch_one_corridor.py", line 183, in render
from gym.envs.classic_control import rendering
File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py", line 29, in <module>
raise ImportError(
ImportError:
Error occurred while running `from pyglet.gl import *`
HINT: make sure you have OpenGL installed. On Ubuntu, you can run 'apt-get install python-opengl'.
If you're running on a server, you may need a virtual frame buffer; something like this should work:
'xvfb-run -s "-screen 0 1400x900x24" python <your_script.py>'
I know that the problem is somewhere in the render step but I unsure how to proceed with debugging. I am currently running the code in a conda virtual environment.
To check if the packages in question were installed correctly, I also tried:
import pyglet
import OpenGL
print("hi")
Which successfully printed "hi", confirming that the packages are installed.
Any help greatly appreciated!
Today I've run into problems trying to use the python-bitcoinlib in a small python program. It worked perfectly a few days ago but today the library seems to be broken (see console output below).
I'm in a Mac with OS X 11.0.1 (yes, I upgraded today, but I would be surprised if that's the cause of the problem).
I've tried several times installing and uninstalling the library and even python, but nothing seems to happen.
Thanks in advance.
>>> from bitcoin.rpc import RawProxy
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
from bitcoin.rpc import RawProxy
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bitcoin/rpc.py", line 48, in <module>
from bitcoin.wallet import CBitcoinAddress, CBitcoinSecret
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bitcoin/wallet.py", line 33, in <module>
import bitcoin.core.key
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/bitcoin/core/key.py", line 34, in <module>
_ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(libeay32, 6): image not found
My solution is not using RawProxy.
Impor this instead:
from bitcoinrpc.authproxy import AuthServiceProxy
And connect to bitcoin core with this sentence or equivalent:
p = AuthServiceProxy("http://%s:%s#127.0.0.1:8332"%(rpcuser, rpcpassword))
I can't program in python at all. I'm just trying to run the grgsm (gnu radio gsm) program, which is written in python. I get following error:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/grgsm/__init__.py", line 48, in <module>
from .grgsm_swig import *
File "/usr/lib/python3.8/site-packages/grgsm/grgsm_swig.py", line 13, in <module>
from . import _grgsm_swig
ImportError: libboost_program_options.so.1.71.0: cannot open shared object file: No such file or directory
Traceback (most recent call last):
File "/usr/bin/grgsm_livemon", line 37, in <module>
from grgsm import arfcn
File "/usr/lib/python3.8/site-packages/grgsm/__init__.py", line 48, in <module>
from .grgsm_swig import *
File "/usr/lib/python3.8/site-packages/grgsm/grgsm_swig.py", line 13, in <module>
from . import _grgsm_swig
ImportError: libboost_program_options.so.1.71.0: cannot open shared object file: No such file or directory
From the above message, I concluded that in the 13th line of the file "/usr/lib/python3.8/site-packages/grgsm/grgsm_swig.py" there is an import of the file "libboost_program_options.so.1.71.0", which is missing. Well, but in the 13th line of this file there is nothing about it. It looks like this:
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.1
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info as _swig_python_version_info
if _swig_python_version_info < (2, 7, 0):
raise RuntimeError("Python 2.7 or later required")
# Import the low-level C/C++ module
if __package__ or "." in __name__:
from . import _grgsm_swig # 13th line
else:
import _grgsm_swig
try:
import builtins as __builtin__
except ImportError:
import __builtin__
I also don't know why python wants this version of boost. If I knew where it is imported, I would simply change it to libboost_program_options.so without the version suffix (because of course I have boost installed).
Solution can be found here. Generally, uninstall it and reinstall its dependencies in the correct order.
The release notes for libarchive state that because of an older version of libarchive being included within MacOS they recommend changing LD_LIBRARY_PATH to point towards the location of the recent copy of libarchive.
I've used this code to try and achieve that but I get an error message when I run the script.
import os
print os.environ.get('LD_LIBRARY_PATH') #Check what the current path is
os.environ['LD_LIBRARY_PATH'] = '/Library/Python/2.7/site-packages/'
print os.environ.get('LD_LIBRARY_PATH') #Check the variable has been set
import libarchive.public
Error:
None
/Library/Python/2.7/site-packages/
Traceback (most recent call last):
File "scratch.py", line 8, in <module>
import libarchive.public
File "/Library/Python/2.7/site-packages/libarchive/public.py", line 1, in <module>
from libarchive.adapters.archive_read import \
File "/Library/Python/2.7/site-packages/libarchive/adapters/archive_read.py", line 7, in <module>
import libarchive.calls.archive_read
File "/Library/Python/2.7/site-packages/libarchive/calls/archive_read.py", line 17, in <module>
c_archive_read_support_filter_all = libarchive.archive_read_support_filter_all
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fb08b741000, archive_read_support_filter_all): symbol not found
I cant find a great answer to this anywhere out there.
It is not clear from the tool documentation, but based on a thread: https://github.com/dsoprea/PyEasyArchive/issues/16 I set another environment variable to the place where the underlying c library could be found. In my case, it was put there by homebrew on my mac.
os.environ['LA_LIBRARY_FILEPATH']='/usr/local/opt/libarchive/lib/libarchive.dylib'
import libarchive.public
worked for me.