r/learnpython • • 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?

3 Upvotes

42 comments sorted by

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.

-3

u/Radamand Nov 27 '22

no, I enjoy solving problems, when they are solvable! going on 2 hours now for a simple library import is ridiculous!

6

u/LeeRyman Nov 27 '22

Getting gstreamer and its python introspection libraries working can be a little unintuitive, because you're often mixing installation of required distro packages with required wheels, and hoping the dependencies are correct and fulfilled.

This is definitely a situation where I'd be taking a break, have a ponder about how to troubleshoot the problem differently and try again.

2 hours on a more-complex integration problem is nothing. A fresh look might rule out silly issues like system vs venv environments, different python versions, different GST versions, etc.

2

u/[deleted] Nov 27 '22

Most problems are solvable. Sometimes they are problematic and take a lot of time, but generally, that gets better with more learning/experience.

Reading the error messages and interpreting them is an essential skill that gets easier with more experience. Don't give up, and learn to explain to the rubber duck. It really helps a lot: https://en.m.wikipedia.org/wiki/Rubber_duck_debugging

3

u/WikiSummarizerBot Nov 27 '22

Rubber duck debugging

In software engineering, rubber duck debugging (or rubberducking) is a method of debugging code by articulating a problem in spoken or written natural language. The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line-by-line, to the duck. Many other terms exist for this technique, often involving different (usually) inanimate objects, or pets such as a dog or a cat.

[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5

2

u/Explicit_Pickle Nov 27 '22

They're solvable. It can be frustrating starting out but the more you put into it the more the problems will get more and more interesting, but always solvable

2

u/Boohoolean Nov 27 '22

EVERY problem in life is solvable in one way or another. Perseverance and ingenuity are key.

5

u/[deleted] 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

u/[deleted] Nov 27 '22 edited Nov 27 '22

OK. I got it working. Here are the steps I took.

  1. I created a project folder.

  2. I created a venv in that folder and activated it.

  3. 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-ugly          
  4. I then installed the library itself with pip3 install audioplayer.

  5. 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.

  6. I then installed gi with sudo apt install python3-gi.

  7. I tried again to no avail.

  8. Then I installed vext with

     pip3 install vext
     pip3 install vext.gi
  9. At 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

u/[deleted] 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

u/[deleted] 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.

0

u/Radamand Nov 27 '22

I tried the same import from a command line python3 session, same result

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

u/[deleted] 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

u/[deleted] 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

u/[deleted] Nov 27 '22

Was that supposed to be to the tune of the dreidel song? Because that's how I sang it.

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

u/[deleted] 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

u/33498fff Nov 27 '22

I'd also have an awful time programming if I didn't enjoy solving errors.

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

u/arobotfrog Nov 27 '22

This is why I love programming.

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

u/ReyAlejandro21 Nov 27 '22

Have a little patience, we all pass by that cenario.

1

u/coding-central Nov 27 '22

Have you tried pip installing?

1

u/Guyserbun007 Nov 27 '22

Docker may help

-3

u/QultrosSanhattan Nov 27 '22

or Linux complains

Use windows. Most of those other problems will vanish.

1

u/[deleted] Nov 27 '22

Worst response, quite the contrary, rtfm OP