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

10.5k Views Asked by At
    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.

8

There are 8 best solutions below

0
jooleer On

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.

0
hellomello On

Try running

pip install --upgrade wheel
0
Saarth Desai On

This works to solve the issue:

pip install --upgrade wheel
1
Christopher On

Use the following:

pip install --upgrade setuptools wheel
pip install playsound
0
mattmess1221 On

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
0
AudioBubble On

I also got this error and I fixed it using:

python -m pip install playsound
0
Nikita Mandal On

Just use following

pip install playsound==1.2.2
0
Md.Rakibuz Sultan On

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