相关疑难解决方法(0)

从脚本导入已安装的包会引发"AttributeError:module has no attribute"或"ImportError:无法导入名称"

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

以下代码提出了一个问题AttributeError.

import requests

res = requests.get('http://www.google.ca')
print(res)
Run Code Online (Sandbox Code Playgroud)
Traceback (most recent call last):
  File "/Users/me/dev/rough/requests.py", line 1, in <module>
    import requests
  File "/Users/me/dev/rough/requests.py", line 3, in <module>
    requests.get('http://www.google.ca')
AttributeError: module 'requests' has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)

以下代码提出了一个问题ImportError.

from requests import get

res = get('http://www.google.ca')
print(res)
Run Code Online (Sandbox Code Playgroud)
Traceback (most recent call last):
  File "requests.py", line 1, in <module>
    from requests import get
  File "/Users/me/dev/rough/requests.py", line 1, in <module>
    from requests import get
ImportError: cannot import name 'get' …
Run Code Online (Sandbox Code Playgroud)

python exception python-module shadowing

43
推荐指数
2
解决办法
1万
查看次数

AttributeError:'module'对象没有属性'Number'

不确定是什么导致这个......

我使用"Pillow-3.3.0.win32-py34.exe"安装文件运行Python 3.4.3.

导入图像时带

from PIL import Image
Run Code Online (Sandbox Code Playgroud)

我尝试使用"a.jpg"作为我的图像

img = Image.open("a.jpg")
Run Code Online (Sandbox Code Playgroud)

但是我收到这个错误,

>>> img = Image.open("a.jpg")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\PIL\Image.py", line 2289, in open
    preinit()
  File "C:\Python34\lib\site-packages\PIL\Image.py", line 365, in preinit
    from PIL import JpegImagePlugin
  File "C:\Python34\lib\site-packages\PIL\JpegImagePlugin.py", line 40, in <modu
le>
    from PIL import Image, ImageFile, TiffImagePlugin, _binary
  File "C:\Python34\lib\site-packages\PIL\TiffImagePlugin.py", line 50, in <modu
le>
    from fractions import Fraction
  File "C:\Python34\lib\fractions.py", line 6, in <module>
    from decimal import Decimal …
Run Code Online (Sandbox Code Playgroud)

pillow

2
推荐指数
1
解决办法
2461
查看次数

标签 统计

exception ×1

pillow ×1

python ×1

python-module ×1

shadowing ×1