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!
Related
I have a Python Code to conduct an experiment. To ensure that the Code is working smoothly I wanted to run a trial round via 'otree devserver', but I always get an AttributeError message and I am stuck here. Can anyone help me out?
I have downloaded the Code from GitHub and downloaded all required packages. I am using macOS, otree-5.10.2 and django-4.1.7. Here is my full traceback / error message:
Traceback (most recent call last): File
"/Users/.otreevenv/bin/otree", line 8, in
sys.exit(execute_from_command_line()) File "/Users/.otreevenv/lib/python3.10/site-packages/otree/main.py", line
108, in execute_from_command_line
setup() File "/Users/.otreevenv/lib/python3.10/site-packages/otree/main.py", line
132, in setup
from otree import settings File "/Users/.otreevenv/lib/python3.10/site-packages/otree/settings.py",
line 50, in
OTREE_APPS = get_OTREE_APPS(settings.SESSION_CONFIGS) File "/Users/.otreevenv/lib/python3.10/site-packages/django/conf/__init__.py",
line 94, in __getattr__
val = getattr(_wrapped, name) File "/Users/.otreevenv/lib/python3.10/site-packages/django/conf/__init__.py",
line 270, in __getattr__
return getattr(self.default_settings, name) AttributeError: module 'django.conf.global_settings' has no attribute 'SESSION_CONFIGS'. Did
you mean: 'SESSION_ENGINE'?
I am trying to run this text-to-speech program
I followed instructions verbatim, but when I go to run the first line of code (below)
python tortoise/do_tts.py --text "I'm going to speak this" --voice random --preset fast
I get he following error code:
C:\Users\chase\anaconda3\lib\site-packages\torchaudio\_internal\module_utils.py:99: UserWarning: Failed to import soundfile. 'soundfile' backend is not available.
warnings.warn("Failed to import soundfile. 'soundfile' backend is not available.")
C:\Users\chase\anaconda3\lib\site-packages\paramiko\transport.py:219: CryptographyDeprecationWarning: Blowfish has been deprecated
"class": algorithms.Blowfish,
Traceback (most recent call last):
File "C:\Users\chase\anaconda3\lib\site-packages\soundfile.py", line 152, in <module>
_snd = _ffi.dlopen(_libname)
OSError: cannot load library 'C:\Users\chase\anaconda3\Library\bin\sndfile.dll': error 0x7e
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\chase\anaconda3\lib\site-packages\soundfile.py", line 178, in <module>
_snd = _ffi.dlopen(_os.path.join(_path, '_soundfile_data', _packaged_libname))
OSError: cannot load library 'C:\Users\chase\anaconda3\lib\site-packages\_soundfile_data\libsndfile_64bit.dll': error 0x7e
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\chase\tortoise-tts\tortoise\do_tts.py", line 7, in <module>
from api import TextToSpeech, MODELS_DIR
File "C:\Users\chase\tortoise-tts\tortoise\api.py", line 22, in <module>
from tortoise.utils.audio import wav_to_univnet_mel, denormalize_tacotron_mel
File "C:\Users\chase\anaconda3\lib\site-packages\tortoise-2.4.2-py3.9.egg\tortoise\utils\audio.py", line 4, in <module>
import librosa
File "C:\Users\chase\anaconda3\lib\site-packages\librosa-0.9.2-py3.9.egg\librosa\__init__.py", line 209, in <module>
from . import core
File "C:\Users\chase\anaconda3\lib\site-packages\librosa-0.9.2-py3.9.egg\librosa\core\__init__.py", line 6, in <module>
from .audio import * # pylint: disable=wildcard-import
File "C:\Users\chase\anaconda3\lib\site-packages\librosa-0.9.2-py3.9.egg\librosa\core\audio.py", line 8, in <module>
import soundfile as sf
File "C:\Users\chase\anaconda3\lib\site-packages\soundfile.py", line 189, in <module>
_snd = _ffi.dlopen(_libname)
OSError: cannot load library 'libsndfile.dll': error 0x7e
I expected it to run
Try on linux, it works fine for me.
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)
I'm working on windows with python 3.7.2 and using uszipcode library and import SearchEngine for getting a list of zip codes which start with the argument of the function.
I'm getting the following errors:
Traceback (most recent call last):
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 338, in dbapi
from pysqlite2 import dbapi2 as sqlite
ModuleNotFoundError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/tutorial/tutorial/Zillow/zillow_runfile.py", line 38, in <module>
st = zl.zipcodes_list(st_items=["100", "770"])
File "C:\Users\user\PycharmProjects\tutorial\tutorial\Zillow\zillow_functions.py", line 32, in zipcodes_list
search = SearchEngine()
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\search.py", line 82, in __init__
engine = connect_to_simple_zipcode_db()
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\db.py", line 49, in connect_to_simple_zipcode_db
return engine_creator.create_sqlite(path=simple_db_file_path.abspath)
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\pkg\sqlalchemy_mate\engine_creator.py", line 51, in create_sqlite
return create_engine(_create_sqlite(path), **kwargs)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\engine\__init__.py", line 423, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\engine\strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 343, in dbapi
raise e
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 341, in dbapi
from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name.
File "C:\Users\user\Anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\user\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: entry module not found.
I've tried to install different libraries according to recommendations I found online:
pip install sqlite-devel
pip install sqlite3tools
pip install libsqlite3-dev
for each of the above I got the following error:
Could not find a version that satisfies the requirement "sqlite-devel <from versions: >
No matching distribution found for "sqlite-devel"
def zipcodes_list(st_items):
search = SearchEngine()
# If st_items is a single zipcode string.
if isinstance(st_items, str):
zc_objects = search.by_prefix(st_items)
# If st_items is a list of zipcode strings.
elif isinstance(st_items, list):
zc_objects = [n for i in st_items for n in search.by_prefix(str(i))]
else:
raise ValueError("arg 'st_items' must be of type str or list")
output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects]
return output
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.