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

View all comments

Show parent comments

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.