How to fix "OSError: could not get source code" error when installing playsound?
Asked Answered
B

8

13
    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
      ╰─> [29 lines of output]
          Traceback (most recent call last):
            File "C:\Users\INTEL\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
              main()
            File "C:\Users\INTEL\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
              json_out['return_val'] = hook(**hook_input['kwargs'])
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\INTEL\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
              return hook(config_settings)
                     ^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\INTEL\AppData\Local\Temp\pip-build-env-9ac5eef9\overlay\Lib\site-packages\setuptools\build_meta.py", line 341, in get_requires_for_build_wheel
              return self._get_build_requires(config_settings, requirements=['wheel'])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\INTEL\AppData\Local\Temp\pip-build-env-9ac5eef9\overlay\Lib\site-packages\setuptools\build_meta.py", line 323, in _get_build_requires 
              self.run_setup()
            File "C:\Users\INTEL\AppData\Local\Temp\pip-build-env-9ac5eef9\overlay\Lib\site-packages\setuptools\build_meta.py", line 488, in run_setup
              self).run_setup(setup_script=setup_script)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\INTEL\AppData\Local\Temp\pip-build-env-9ac5eef9\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
              exec(code, locals())
            File "<string>", line 6, in <module>
            File "C:\Users\INTEL\AppData\Local\Programs\Python\Python311\Lib\inspect.py", line 1270, in getsource
              lines, lnum = getsourcelines(object)
                            ^^^^^^^^^^^^^^^^^^^^^^
            File "C:\Users\INTEL\AppData\Local\Programs\Python\Python311\Lib\inspect.py", line 1252, in getsourcelines
              lines, lnum = findsource(object)
                            ^^^^^^^^^^^^^^^^^^
            File "C:\Users\INTEL\AppData\Local\Programs\Python\Python311\Lib\inspect.py", line 1081, 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.

I tried to update Python version and pip version.

Balbriggan answered 22/4, 2023 at 8:29 Comment(0)
E
24

This works to solve the issue:

pip install --upgrade wheel
Escarole answered 5/7, 2023 at 20:27 Comment(0)
E
11

Use the following:

pip install --upgrade setuptools wheel
pip install playsound
Electrophysiology answered 4/10, 2023 at 16:44 Comment(1)
Thank you, this worked in my case. When only upgrading the wheel the issue still persist. I am using Python version 3.12.1Hayner
O
6

Try running

pip install --upgrade wheel
Oryx answered 7/6, 2023 at 4:5 Comment(0)
A
1

Looks like you're running python 3.11 while playsound 1.3.0 currently supports up to python 3.9. Try downgrading or using a venv like Anaconda to have multiple python versions available.

Anagnorisis answered 22/4, 2023 at 9:16 Comment(0)
S
0

playsound 1.3.0 does not currently have a whl, and the sdist version (.tar.gz) has a bug when installed with pip.

If you don't want to wait for the fix and you have git installed, you can install the fixed version from my github.

pip install git+https://github.com/killjoy1221/playsound.git
Slapstick answered 1/11, 2023 at 17:27 Comment(0)
D
0

I also got this error and I fixed it using:

python -m pip install playsound
Disinclination answered 29/12, 2023 at 18:41 Comment(0)
M
0

Just use following

pip install playsound==1.2.2
Maurizio answered 1/1 at 7:3 Comment(0)
A
0

It is an issue related to building the wheel for the playsound module:It worked for me this way.

Step 1:

pip install --upgrade setuptools

Step 2: After upgrading setuptools, try installing the playsound module again

pip install playsound

Step 3: Make sure you are using Python 3.x

pip install playsound --no-cache-dir

Step 4:

pip install playsound --only-binary playsound
Artimas answered 18/1 at 0:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.