Unable to use module playsound

Hello!
I would like to use module playsound, but it can not be loaded. I’m running python3.12on Ubuntu 24.04.3.

If I try to install this module with pip install playsound, I get:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

There is no python3-playsound in Ubuntu apt package manager. pipx install playsound produces:

...
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

and also

error: subprocess-exited-with-error
OSError: could not get source code

I installed python3-wheeland also python3-full, but with no effect.

If I try to create a venv and from inside the venv I run pip install playsound I get the error

...
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

I also tried with module playsound3, which can be installed with pip inside a venv, but when I run the script using playsound from the root directory of the venv, it prints

ModuleNotFoundError: No module named 'playsound3

What could it be the problem? I can either use playsound or playsound3.

You are cutting of some of the output. The text before what you showed is going to tell you what went wrong.

This is the full output:

Collecting playsound
Using cached playsound-1.3.0.tar.gz (7.7 kB)
Installing build dependencies … done
Getting requirements to build wheel … error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [28 lines of output]
Traceback (most recent call last):
File “/path/to/my/venv/my_venv/test1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 353, in 
main()
File “/path/to/my/venv/my_venv/test1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 335, in main
json_out[‘return_val’] = hook(**hook_input[‘kwargs’])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/path/to/my/venv/my_venv/test1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py”, line 118, in get_requires_for_build_wheel
return hook(config_settings)
^^^^^^^^^^^^^^^^^^^^^
File “/tmp/pip-build-env-t4rdiyab/overlay/lib/python3.12/site-packages/setuptools/build_meta.py”, line 331, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=
)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/tmp/pip-build-env-t4rdiyab/overlay/lib/python3.12/site-packages/setuptools/build_meta.py”, line 301, in _get_build_requires
self.run_setup()
File “/tmp/pip-build-env-t4rdiyab/overlay/lib/python3.12/site-packages/setuptools/build_meta.py”, line 512, in run_setup
super().run_setup(setup_script=setup_script)
File “/tmp/pip-build-env-t4rdiyab/overlay/lib/python3.12/site-packages/setuptools/build_meta.py”, line 317, in run_setup
exec(code, locals())
File “”, line 6, in 
File “/usr/lib/python3.12/inspect.py”, line 1278, in getsource
lines, lnum = getsourcelines(object)
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/inspect.py”, line 1260, in getsourcelines
lines, lnum = findsource(object)
^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.12/inspect.py”, line 1089, in findsource
raise OSError(‘could not get source code’)
OSError: could not get source code
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

That’s the output when you install playsound. What’s the full output when you install playsound3? For the record, you can completely disregard playsound (which is no longer maintained) and just use playsound3.

2 Likes

As regards playsound3,

It can successfully be installed inside the venv with pip install playsound3. The error was due to the fact that I was not recalling the correct python executable provided by the venv. Now it works, using in the script the shebang

#!/path/to/my/venv/bin/python

Thank you for all the suggestions!