python已安装的模块导入失败_python-从脚本导入已安装的软件包会引发“ AttributeError:模块没有属性”或“ ImportError:无法导入名称”...

我有一个名为requests的脚本,用于导入请求包。 该脚本无法访问包中的属性,也无法导入它们。 为什么这不起作用,我该如何解决?

以下代码引发requests。

import requests

res = requests.get('http://www.google.ca')

print(res)

Traceback (most recent call last):

File "/Users/me/dev/rough/requests.py", line 1, in

import requests

File "/Users/me/dev/rough/requests.py", line 3, in

requests.get('http://www.google.ca')

AttributeError: module 'requests' has no attribute 'get'

The following code raises an requests.

from requests import get

res = get('http://www.google.ca')

print(res)

Traceback (most recent call last):

File "requests.py", line 1, in

from requests import get

File "/Users/me/dev/rough/requests.py", line 1, in

from requests import get

ImportError: cannot import name 'get'

或从requests包内的模块导入的代码:

from requests.auth import AuthBase

Traceback (most recent call last):

File "requests.py", line 1, in

from requests.auth import AuthBase

File "/Users/me/dev/rough/requests.py", line 1, in

from requests.auth import AuthBase

ImportError: No module named 'requests.auth'; 'requests' is not a package

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,你遇到了一个名为`AttributeError: '_SoundFileInfo' object has no attribute 'title'`的错误。这个错误通常是由于soundfile模块中的`_SoundFileInfo`对象缺少`title`属性引起的。 为了解决这个问题,你可以尝试以下方法: 1. 确保soundfile模块已正确安装。你可以使用以下命令检查soundfile模块的版本: ```shell pip show soundfile ``` 如果soundfile模块安装或版本过低,你可以使用以下命令安装或升级soundfile模块: ```shell pip install --upgrade soundfile ``` 2. 检查你的代码中是否正确使用了soundfile模块。请确保你已经正确导入了soundfile模块,并且在使用`_SoundFileInfo`对象之前,先创建了一个soundfile对象。例如: ```python import soundfile as sf # 打开音频文件 data, samplerate = sf.read('audio.wav') # 创建SoundFileInfo对象 info = sf.info('audio.wav') # 使用title属性 print(info.title) ``` 3. 如果以上方法仍然无法解决问题,你可以尝试降低librosa和matplotlib的版本。根据你提供的引用和引用,你已经将librosa降级到了0.9.2,并重新安装了matplotlib。这可能是因为librosa和matplotlib之间的版本兼容性问题导致的。你可以使用以下命令降级librosa和matplotlib的版本: ```shell pip install librosa==0.9.2 pip install matplotlib==3.7.0 ``` 请注意,降级版本可能导致其他依赖项出现问题,因此在执行此操作之前,请确保你已经备份了你的代码和环境。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值