r/learnpython • u/Radamand • Nov 27 '22
This is why I hate programming
It invarably happens, whenever I try to start a new VERY simple project that either python complains about something or Linux complains, or spyder complains, or who knows who might complain about something being wrong. Then I end up spending the next hour pouring over google search results trying to find ANYONE who has had this problem before. I find, and try half a dozen different 'fixes' that none of them work and I end up tearing my hair out.
Then I end up here, begging anyone to solve my problem.
I wanted to write a simple little script that would play audio files. I found one named AudioPlayer that seems to suit my needs. I install the module and write about a dozen lines of code, and run it only to be prompted with 'No module named 'gi''.
Funny, I don't recall ever asking for a module named gi before, regardless, the file refuses to play.
again, I pour thru google search results trying to find a solution, to no avail. I've tried half as dozen (or more) different 'solutions' without success.
I am running anaconda on Ubuntu with Python 3.9.12.
Does anyone have an idea how I can solve this?
5
Nov 27 '22
Link to the library you're trying to use: there are many projects called "AudioPlayer". I'll see if I can replicate the problem on my system.
2
u/Radamand Nov 27 '22
https://pypi.org/project/audioplayer/
from audioplayer import AudioPlayer
Traceback (most recent call last):
File ~/MusicLibraryCleanupTool.py:8 in <module>
from audioplayer import AudioPlayer
File ~/anaconda3/lib/python3.9/site-packages/audioplayer/__init__.py:12 in <module>
from .audioplayer_linux import AudioPlayerLinux as AudioPlayer
File ~/anaconda3/lib/python3.9/site-packages/audioplayer/audioplayer_linux.py:7 in <module>
import gi
ModuleNotFoundError: No module named 'gi'9
Nov 27 '22 edited Nov 27 '22
OK. I got it working. Here are the steps I took.
I created a project folder.
I created a venv in that folder and activated it.
I tried to install these libraries listed in the library's README but they failed.
sudo apt-get install python-gst-1.0 \ gir1.2-gstreamer-1.0 \ gstreamer1.0-tools \ gir1.2-gst-plugins-base-1.0 gstreamer1.0-plugins-good \ gstreamer1.0-plugins-uglyI then installed the library itself with
pip3 install audioplayer.At this point, I tried to run the example program they have in the project's README from inside my virtual environment.
from audioplayer import AudioPlayer AudioPlayer("path/to/somemusic.mp3").play(block=True)but I got the same error as you.
I then installed
giwithsudo apt install python3-gi.I tried again to no avail.
Then I installed vext with
pip3 install vext pip3 install vext.giAt this point, the program runs. These two may be the only packages you need to install, but I went ahead and included the others in case they were necessary as I didn't immediately uninstall them.
Hope that helps!
-10
u/Radamand Nov 27 '22
Tried that awhile ago, doesn't work.
3
Nov 27 '22
Just to confirm, have you made sure you're installing the modules in the virtual environment you're running your program in rather than with your system python?
-7
u/Radamand Nov 27 '22
I am not using a venv so, yes.
6
Nov 27 '22
I just ask because sometimes your text editor or maybe even Anaconda (I'm not that familiar with Anaconda) will automatically set one up and then you think you're pip installing with the same version of python you're running your program with, but it turns out not to be the case. It's happened to me.
If not, then sorry. I don't know what to say except that it works for me.
→ More replies (1)1
u/invaliddrum Nov 27 '22
Anaconda creates it's own virtual environment (a root one and then as many others as you wish) and you'll typically install packages with conda install rather than using pip which often fails within a conda environment.
Not as many packages are available through conda and for a little project like this you are probably better off using your systems python and creating a regular virtual envs.0
Nov 27 '22
[deleted]
0
u/Radamand Nov 27 '22
sudo apt-get install python-gst-1.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python-gst-1.0
E: Couldn't find any package by glob 'python-gst-1.0'
E: Couldn't find any package by regex 'python-gst-1.0'
5
u/Guideon72 Nov 27 '22
Show us the code you’ve written and we can get a better idea of where the error is coming from.
0
u/Radamand Nov 27 '22
You don't need ANY code to reproduce the error; it fails on the IMPORT itself
from audioplayer import AudioPlayer
Traceback (most recent call last):
File ~/MusicLibraryCleanupTool.py:8 in <module>
from audioplayer import AudioPlayer
File ~/anaconda3/lib/python3.9/site-packages/audioplayer/__init__.py:12 in <module>
from .audioplayer_linux import AudioPlayerLinux as AudioPlayer
File ~/anaconda3/lib/python3.9/site-packages/audioplayer/audioplayer_linux.py:7 in <module>
import gi
ModuleNotFoundError: No module named 'gi'
2
u/Radamand Nov 27 '22
The prerequisit package python-gst-1.0 was not installing.
I found the correct package python3-gst-1.0 and got it installed, uninstalled/reinstall audioplayer, still same result.
ModuleNotFoundError: No module named 'gi'
2
u/Radamand Nov 27 '22
Reinstalling PyGObject got the import working on command-line python3, spyder still complains...
38
Nov 27 '22
OP: This is not about programming but about really understanding the error messages.
Like a fine wine, you need to really appreciate the error message before you can enjoy it.
Don’t just get angry that there is a message. It’s telling you the answer.
I feel like a haiku or ode to error messages is in order, but I’m not creative enough,
8
u/thePurpleAvenger Nov 27 '22
I used to have a good song for pointers...
POINTERS POINTERS POINTERS... I put you in my code!
POINTERS POINTERS POINTERS... Where the hell you go?!
6
7
u/synthphreak Nov 27 '22
Errors show the way.
You should learn to read them well.
Future you says thanks.
13
u/Guideon72 Nov 27 '22
There we go; so, YOUR script is attempting to import AudioPlayer, and THEIR scripts are attempting to do the import that’s failing. That would indicate that a prerequisite for that package has not been installed. Did you go through all of those before you installed audioplayer?
2
u/Radamand Nov 27 '22
FINAL UPDATE:
After banging my head against the keyboard for a couple of hours I decided that the audioplayer library was NOT going to work.
Switched to another library (just_playback) and found that it, also, would not work.
Finally switched to using pygame library, it works flawlessly!
Thanks for all the help guys, I really appreciate it!
3
Nov 27 '22
I get venting, but these are problems you are creating for yourself.
Test the import before writing code.
Read the error messages.
Don't blame the library for an issue that is clearly yours.
Use virtual environments to avoid conflicting imports.
2
1
u/SE_WA_VT_FL_MN Nov 27 '22
Honest question here: do others get these issues and find happiness in it? That has always been my experience. Run it, it bugs out, stomp a dozen dumb mistakes, then puzzle away at another basically syntax error or two, and then start throwing a bunch of tests to find new dumb mistakes. Iterate some part to be a bit better (or more likely at least more coherent).
Typically a few days later I discover a module that would is just import x, x.solveproblem().
1
u/KingsmanVince Google YOUR questions and errors first Nov 27 '22 edited Nov 27 '22
It invarably happens, whenever I try to start a new VERY simple project that either python complains about something or Linux complains, or spyder complains, or who knows who might complain about something being wrong.
This is pretty much on you. You don't read the docs, google it, or even try to use things as intended ways. Hence, something always breaks. If things always go wrong whenever you start a simple project, you should look at yourself and ask "do I understand/learn this aspect/software/concept carefully?"
Then I end up spending the next hour pouring over google search results trying to find ANYONE who has had this problem before
Do you know why you can't find anyone with similar problems? Because they do right stuff and you don't.
1
1
u/snekk420 Nov 27 '22
In my experience for simple scripting just use pip and as little libraries as possible and you will have a pleasant experience. A problem in programming is that there is a lot of people writing shitty code. Instead of debugging all the “helper” libraries and tools you can focus on your code. If you are working on a big project in a company these 3rd party tools will help but they will most likely be tuned by an experienced developer.
1
u/Nunaldinho Nov 27 '22
I can sympathise with OP, but I guess the trick is to get to a setup with which you are familiar and know there are no incompatibilities between packages and whatnot. And then focus on the coding. But I'm a noob myself, so what do I know.
1
u/invaliddrum Nov 27 '22
You say you are using Anaconda which I imagine is how you installed Spyder. Conda has it's own virtual environments and repositories and you install packages here with conda install. It sounds like you've been trying to install packages from PyPi with pip which often doesn't go well within a conda environment. Try checking out https://www.anaconda.com/blog/understanding-conda-and-pip
1
1
1
-3
u/QultrosSanhattan Nov 27 '22
or Linux complains
Use windows. Most of those other problems will vanish.
1
16
u/KimPeek Nov 27 '22
Bit of reality for you: programming probably isn't the best activity to spend your time on if you get this frustrated from a problem. Programming is largely a cycle of trying to do something, being interrupted by a problem, working to overcome that problem, then continuing to the next problem. You may hate that, and that's completely fine. Some of us enjoy problem solving, but it's well established that programming can be frustrating and is not for everyone.