soonkuayue 发表于 2024-6-20 11:50:00

不能正常导入库playsound

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting playsound
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/67/8c/c9f46b4b194126c4abb12e96321a6bea5c8dcc5c0e4d97622c14dfabe299/playsound-1.3.0.tar.gz (7.7 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'error'

DEPRECATION: Loading egg at c:\program files\python312\lib\site-packages\pip-24.0-py3.12.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330
DEPRECATION: Loading egg at c:\program files\python312\lib\site-packages\setuptools-69.1.1-py3.12.egg is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330
error: subprocess-exited-with-error

Getting requirements to build wheel did not run successfully.
exit code: 1


Traceback (most recent call last):
    File "C:\Program Files\Python312\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
      main()
    File "C:\Program Files\Python312\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:\Program Files\Python312\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\Administrator\AppData\Local\Temp\pip-build-env-p7gt8wb1\overlay\Lib\site-packages\setuptools\build_meta.py", line 327, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=[])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-p7gt8wb1\overlay\Lib\site-packages\setuptools\build_meta.py", line 297, in _get_build_requires
      self.run_setup()
    File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-p7gt8wb1\overlay\Lib\site-packages\setuptools\build_meta.py", line 497, in run_setup
      super().run_setup(setup_script=setup_script)
    File "C:\Users\Administrator\AppData\Local\Temp\pip-build-env-p7gt8wb1\overlay\Lib\site-packages\setuptools\build_meta.py", line 313, in run_setup
      exec(code, locals())
    File "<string>", line 6, in <module>
    File "C:\Program Files\Python312\Lib\inspect.py", line 1282, in getsource
      lines, lnum = getsourcelines(object)
                  ^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Program Files\Python312\Lib\inspect.py", line 1264, in getsourcelines
      lines, lnum = findsource(object)
                  ^^^^^^^^^^^^^^^^^^
    File "C:\Program Files\Python312\Lib\inspect.py", line 1093, in findsource
      raise OSError('could not get source code')
OSError: could not get source code


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.


使用pycharm 不能导入库playsound,提示如上,怎么解决。

FishC 发表于 2024-6-20 11:50:24

根据你提供的错误信息来看,问题可能出在 `pip` 和 `setuptools` 的版本或者配置上。我们可以尝试以下几个步骤来解决这个问题:

1. **更新 `pip` 和 `setuptools`:**
   打开你的命令行工具(cmd, PowerShell, 或者 PyCharm 的终端),然后运行以下命令来更新 `pip` 和 `setuptools`:
   python -m pip install --upgrade pip setuptools

2. **使用国内镜像源重新安装 `playsound`:**
   可以使用清华的镜像源来重新安装 `playsound`,避免因为网络问题导致的安装失败:
   pip install playsound -i https://pypi.tuna.tsinghua.edu.cn/simple

3. **尝试安装具体版本的 `playsound`:**
   有时候指定版本号可以避免某些版本之间的兼容性问题:
   pip install playsound==1.2.2 -i https://pypi.tuna.tsinghua.edu.cn/simple

4. **检查 Python 和 pip 版本:**
   确认你使用的 Python 版本和 pip 版本是最新的,尤其是 Python 3.12 这种相对较新的版本,有时候库的兼容性问题可能需要特定的版本来解决。

5. **如果上述步骤都未解决问题,考虑手动安装:**
   可以下载 `playsound` 的源码包,然后手动安装。你可以从 (https://pypi.org/project/playsound/#files) 下载 tar.gz 或 zip 包,解压后在目录中运行:
   python setup.py install

如果你愿意提供上传的文件内容,也许我可以更具体地帮助你检查安装过程中出现的问题。请告知你希望怎么处理该文件。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

soonkuayue 发表于 2024-6-20 11:59:16

使用低版本的playsound就可以了。

FishC 发表于 2024-6-20 12:03:04

soonkuayue 发表于 2024-06-20 11:59
使用低版本的playsound就可以了。

好的,让我来看看你上传的文件内容,看看有没有什么线索能帮助解决问题。

首先,我会解压文件并查看其内容。

import tarfile
import os

file_path = '/mnt/data/2024-06-20-12-VMnpl5XbKcQpWy9rIkkv.gz'
extracted_path = '/mnt/data/extracted'

# Create a directory for extraction
os.makedirs(extracted_path, exist_ok=True)

# Extract the tar.gz file
with tarfile.open(file_path, 'r:gz') as tar:
    tar.extractall(path=extracted_path)

# List the contents of the extracted directory
extracted_files = os.listdir(extracted_path)
extracted_files

让我来解压文件并查看里面的内容。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
页: [1]
查看完整版本: 不能正常导入库playsound