TaylorSMarks / playsound

Pure Python, cross platform, single function module with no dependencies for playing sounds.
Other
517 stars 114 forks source link

FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/python3' #81

Open cheryllium opened 3 years ago

cheryllium commented 3 years ago

Hello there, and thanks for the great library! (I love that it's cross platform and has no dependencies!)

I'm on NixOS 20.09. When I tried the basic example:

import playsound from playsound
playsound(AUDIO_FILE) # path to file

There was an error:

Traceback (most recent call last):
  File "main.py", line 34, in <module>
    playsound(AUDIO_FILE)
  File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 254, in <lambda>
    playsound = lambda sound, block = True: _playsoundAnotherPython('/usr/bin/python3', sound, block, macOS = False)
  File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 229, in _playsoundAnotherPython
    t.join()
  File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 218, in join
    raise self.exc
  File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 211, in run
    self.ret = self._target(*self._args, **self._kwargs)
  File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 226, in <lambda>
    t = PropogatingThread(target = lambda: check_call([otherPython, playsoundPath, _handlePathOSX(sound) if macOS else sound]))
  File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/python3'

It looks like it's trying to use /usr/bin/python, which doesn't exist on my system. But even if it did, it would've still used the wrong python, since I'm running this from inside a virtual env. (The correct python would be the virtual env's python, that is, /home/cheshire/CODE/project/.venv/bin/python)

This might be fixed by locating the current python on the system (e.g. which python) and using that instead of a hard-coded /usr/bin/python3 value.

TaylorSMarks commented 3 years ago

Hello,

Do you have gstreamer installed? I believe it’s part of the standard gnome desktop installation.

It wasn’t able to find the gi module, which should be installed in the system python if you have gstreamer, so it’s looking for the system Python.

Handling linux is difficult because there’s so many millions of different ways everything could be setup. For now, it’s more focused on Linux with gnome… in the future, I’d like to add in kde stuff, although that may be difficult to test in Travis-CI.

Taylor

Sent from my iPhone

On Aug 1, 2021, at 20:15, C. Yang @.***> wrote:

 Hello there, and thanks for the great library! (I love that it's cross platform and has no dependencies!)

I'm on NixOS 20.09. When I tried the basic example:

import playsound from playsound playsound(AUDIO_FILE) # path to file There was an error:

Traceback (most recent call last): File "main.py", line 34, in playsound(AUDIO_FILE) File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 254, in playsound = lambda sound, block = True: _playsoundAnotherPython('/usr/bin/python3', sound, block, macOS = False) File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 229, in _playsoundAnotherPython t.join() File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 218, in join raise self.exc File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 211, in run self.ret = self._target(*self._args, self._kwargs) File "/home/cheshire/CODE/project/.venv/lib/python3.8/site-packages/playsound.py", line 226, in t = PropogatingThread(target = lambda: check_call([otherPython, playsoundPath, _handlePathOSX(sound) if macOS else sound])) File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 359, in check_call retcode = call(*popenargs, *kwargs) File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 340, in call with Popen(popenargs, kwargs) as p: File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 854, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/nix/store/z65l1jqvxa58zzwwa3bvglb6asj4y8cv-python3-3.8.5/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/python3' It looks like it's trying to use /usr/bin/python, which doesn't exist on my system. But even if it did, it would've still used the wrong python, since I'm running this from inside a virtual env. (The correct python would be the virtual env's python, that is, /home/cheshire/CODE/project/.venv/bin/python)

This might be fixed by locating the current python on the system (e.g. which python) and using that instead of a hard-coded /usr/bin/python3 value.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

cheryllium commented 3 years ago

Oh, it looks like I misunderstood the error entirely. Thank you! Yeah, I'm using KDE, so that would be why.

Maybe I can try to add that support then. Do you happen to know how it would be implemented for KDE?

TaylorSMarks commented 3 years ago

I believe the name of KDE's media component is phonon. Take a look here for an example of it being used:

https://techbase.kde.org/Phonon/Python

The delayedInit method creates a Phonon.MediaObject and Phonon.AudioOutput and then links them together with Phonon.createPath(self.m_media, audioOutput). Then in the play method it uses setCurrentSource(Phonon.MediaSource(self.m_model.filePath(index)) and then calls play.

Check out playsound and try to modify it until you can get the unit tests (python test.py) to pass on your own machine.

Then I'd like .travis.yml to be modified so that Travis-CI is automatically testing that this runs on both gnome and kde (in addition to Mac and Windows).

Once it's all working, I'll be happy to look at a PR, pull it in, and make an updated release on pypi.

yalattas commented 2 years ago

I am experiencing same error and I couldn't understand the solution. I understood that I need to install gstreamer in order to make plugins works. I tried to install it on backend python container but it failed via apt Here is the error trace

backend   | Internal Server Error: /
backend   | Traceback (most recent call last):
backend   |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
backend   |     response = get_response(request)
backend   |   File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
backend   |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
backend   |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
backend   |     return self.dispatch(request, *args, **kwargs)
backend   |   File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch
backend   |     return handler(request, *args, **kwargs)
backend   |   File "/app/apps/main/views.py", line 16, in get
backend   |     paginator= Paginator(play_audio(), 1)
backend   |   File "/app/apps/main/service.py", line 5, in play_audio
backend   |     return playsound(f'{settings.BASE_DIR}/media/example.mp3', True)
backend   |   File "/usr/local/lib/python3.9/site-packages/playsound.py", line 254, in <lambda>
backend   |     playsound = lambda sound, block = True: _playsoundAnotherPython('/usr/bin/python3', sound, block, macOS = False)
backend   |   File "/usr/local/lib/python3.9/site-packages/playsound.py", line 229, in _playsoundAnotherPython
backend   |     t.join()
backend   |   File "/usr/local/lib/python3.9/site-packages/playsound.py", line 218, in join
backend   |     raise self.exc
backend   |   File "/usr/local/lib/python3.9/site-packages/playsound.py", line 211, in run
backend   |     self.ret = self._target(*self._args, **self._kwargs)
backend   |   File "/usr/local/lib/python3.9/site-packages/playsound.py", line 226, in <lambda>
backend   |     t = PropogatingThread(target = lambda: check_call([otherPython, playsoundPath, _handlePathOSX(sound) if macOS else sound]))
backend   |   File "/usr/local/lib/python3.9/subprocess.py", line 368, in check_call
backend   |     retcode = call(*popenargs, **kwargs)
backend   |   File "/usr/local/lib/python3.9/subprocess.py", line 349, in call
backend   |     with Popen(*popenargs, **kwargs) as p:
backend   |   File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
backend   |     self._execute_child(args, executable, preexec_fn, close_fds,
backend   |   File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
backend   |     raise child_exception_type(errno_num, err_msg, err_filename)
backend   | FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/python3'
backend   | [07/Jan/2022 03:32:51] "GET / HTTP/1.0" 500 121859

I tried to install pygobject but it failed to install

 pip install pygobject

My related code in service.py

from django.conf import settings
from playsound import playsound

def play_audio():
    return playsound(f'{settings.BASE_DIR}/media/example.mp3')

Related code in views.py

from django.shortcuts import render
from django.views.generic import ListView
from .service import play_audio

class mainView(ListView):
    template_name = 'index.html'

    def get(self, request):
        context={"file":play_audio()}
        return render(request, self.template_name, context)

Related code in template/index.html

<html>
    <header>
        {% load static %}
        <title>website Title</title>
    </header>
    <body>
        <audio id="Player" autoplay>
            <source src="{{file}}"/>
        </audio>
    </body>
    <script src="{% static './script.js' %}" />
</html>

BASE_DIR value is /app and there is a file in both containers nginx and backend at the same path which is `media/example.mp3'

Eventually it will be via model layer