Importing pygame raises an ImportError - python

I've been using pygame and python for a while now, and never has pygame ever raised this issue:
Traceback (most recent call last):
File "dodgeball.py", line 1, in <module>
import pygame
File "/Library/Python/2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Python/2.7/site-packages/pygame/base.so, 2): Library not loaded:
#executable_path/../Frameworks/SDL.framework/Versions/A/SDL
Referenced from: /Library/Python/2.7/site-packages/pygame/base.so
Reason: unsafe use of #executable_path in /Library/Python/2.7/site-packages/pygame/base.so with restricted binary
I've been installing heaps of python packages like pip, Distribute, py2app and more so could some of those things be "breaking" pygame?

You may have 2 SDL libraries installed, find all occurrences of sdl and reinstall just one, or remove 1 and leave the other.

Related

How do I install GNU Radio in a Python virtualenv

I am trying to get gnuradio to work in a virtualenv. I want to keep my system somewhat clean and my project needs Python 3.9, but my system Python is 3.8 (Ubuntu 20.04.4 LTS).
I install it using sudo apt install gnuradio, but then it ends up in the system dist-packages and I can't import it in my virtualenv. The imports work fine when running the system Python.
I have tried to recreate my virtualenv to use system packages:
python3.9 -m venv --system-site-packages venv
This at least made my virtualenv able to find gnuradio, but when I try importing stuff it fails in several different ways.
>>> from gnuradio import uhd
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py", line 21, in _prepare_uhd_python
from . import uhd_python
ImportError: cannot import name 'uhd_python' from partially initialized module 'gnuradio.uhd' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py", line 68, in <module>
_prepare_uhd_python()
File "/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py", line 26, in _prepare_uhd_python
from . import uhd_python
ImportError: cannot import name 'uhd_python' from partially initialized module 'gnuradio.uhd' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py)
>>> import pmt
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pmt/__init__.py", line 34, in <module>
from .pmt_python import *
ModuleNotFoundError: No module named 'pmt.pmt_python'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pmt/__init__.py", line 38, in <module>
from .pmt_python import *
ModuleNotFoundError: No module named 'pmt.pmt_python'
I have struggled with this for several days now and found no solution. Is it even possible to run GNU Radio from within a virtualenv?
I have struggled with this for several days now and found no solution.
Your distro's GNU Radio package is built against your distro's python, so you can't use it with a different python.
So, this is expected.
Is it even possible to run GNU Radio from within a virtualenv?
Sure, you'd need to build it from that virtualenv as well, and tell cmake -DCMAKE_INSTALL_PREFIX=/path/to/virtualenv/ to install into it.
We have a pretty nice anaconda packager, so installing GNU Radio into a Python prefix using conda might be the easiest alternative to that.
Alternatively:
Ubuntu 20.04.4 LTS
There's a new Ubuntu LTS version out! If you go for a system upgrade to Ubuntu 22.04 LTS, you get Python 3.10, and a current GNU Radio 3.10.1 "for free".

ModuleNotFoundError: No module named 'Quartz'

I'm trying to work on python3 and using mac. I have installed pyobjc-core and pyobjc, but the error said Quartz not found. I'm very new to this kind of installing. Is there any solution?
Here is my error from pycharm:
Traceback (most recent call last):
File "/Users/Thyme/PycharmProjects/DinosourBot/venv/lib/python3.6/site-packages/pyautogui/_pyautogui_osx.py", line 5, in <module>
import Quartz
ModuleNotFoundError: No module named 'Quartz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Thyme/PycharmProjects/DinosourBot/Bot.py", line 2, in <module>
import pyautogui
File "/Users/Thyme/PycharmProjects/DinosourBot/venv/lib/python3.6/site-packages/pyautogui/__init__.py", line 110, in <module>
from . import _pyautogui_osx as platformModule
File "/Users/Thyme/PycharmProjects/DinosourBot/venv/lib/python3.6/site-packages/pyautogui/_pyautogui_osx.py", line 7, in <module>
assert False, "You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html"
AssertionError: You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html
Process finished with exit code 1
In case anyone stumbles here use:
pip install pyobjc-framework-Quartz
I have solved the problem by
installing pyobjc-framework-Quartz,
it's provided by pycharm
I'd suggest it's best to install all of pyObjC, rather than just specific frameworks. Invariably, if you're working with Quartz, you're going to need various CoreFoundation objects and constants at the very least. To say nothing of AppKit, or other frameworks, depending on what you're doing.
pip install pyobjc (or pip3) should install everything and let you import Quartz. (It works for me on several pythons!)

when I run the pyaudio program I got this error, how can l resolve this

I got the error
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "/Users/huangjinxue/Documents/python/workspace/pyMusic/music-pyaudio.py", line 2, in <module>
import pyaudio
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyaudio.py", line 116, in <module>
import _portaudio as pa
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_portaudio.so, 2): Symbol not found: _PaMacCore_SetupChannelMap
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_portaudio.so
Expected in: dynamic lookup
How can i resolve it, i want to use pyaudio play music list
I am guessing from the error messages that you are on either OS-X or Linux - in either case you have an unmet dependency on the PortAudio package.
You need to either install it from your package manager or to download, build & install it from here.

Python ImportError: DLL load failed: The specified module could not be found

I recently downloaded and installed pygame. I tested it with the following code.
import pygame
I received the following error:
C:\Python34>python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import pygame
File "C:\Python34\lib\site-packages\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
I currently have Python 3.4 32 bit and have downloaded pygame-1.9.2a0.win32-py3.2 and installed it. I tried uninstalling and reinstalling multiple times. What am I doing wrong?
Pygame doesn't work for Python 3.4. The pygame that you downloaded is for Python 3.2. If you download Python 3.2, you should be able to use pygame.

Pygame installed, but not working

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.

Categories

Resources