遇到 Python3 问题, import requests 库出现 AttributeError: '_SixMetaPathImporter' object... - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cpluspython
V2EX    Python

遇到 Python3 问题, import requests 库出现 AttributeError: '_SixMetaPathImporter' object...

  •  
  •   cpluspython 2020-04-21 01:45:09 +08:00 3108 次点击
    这是一个创建于 2000 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码内容如下

    # -*- coding:utf-8 -*- #! /usr/bin/env python3 import requests #引入 requests 库 

    运行代码后

    出现错误提示

    AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec',
    TypeError: 'int' object is not callable

    完整错误提示如下

    Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 900, in _find_spec AttributeError: '_SixMetaPathImporter' object has no attribute 'find_spec' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/noogler/Documents/python_files_sublimetext3/practice/draft7.py", line 3, in <module> import requests File "/usr/local/lib/python3.7/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/usr/local/lib/python3.7/site-packages/urllib3/__init__.py", line 7, in <module> from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 11, in <module> from .exceptions import ( File "/usr/local/lib/python3.7/site-packages/urllib3/exceptions.py", line 2, in <module> from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 963, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 902, in _find_spec File "<frozen importlib._bootstrap>", line 879, in _find_spec_legacy File "<frozen importlib._bootstrap>", line 449, in spec_from_loader File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 212, in is_package return hasattr(self.__get_module(fullname), "__path__") File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 116, in __getattr__ _module = self._resolve() File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 113, in _resolve return _import_module(self.mod) File "/usr/local/lib/python3.7/site-packages/urllib3/packages/six.py", line 82, in _import_module __import__(name) File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 71, in <module> import email.parser File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/parser.py", line 12, in <module> from email.feedparser import FeedParser, BytesFeedParser File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/feedparser.py", line 27, in <module> from email._policybase import compat32 File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_policybase.py", line 9, in <module> from email.utils import _has_surrogates File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/utils.py", line 33, in <module> from email._parseaddr import quote File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_parseaddr.py", line 16, in <module> import time, calendar File "/Users/noogler/Documents/python_files_sublimetext3/practice/calendar.py", line 9, in <module> cal = calendar.month(year,month) TypeError: 'int' object is not callable [Finished in 0.1s with exit code 1] [cmd: ['/usr/local/bin/python3', '-u', '/Users/noogler/Documents/python_files_sublimetext3/practice/draft7.py']] [dir: /Users/noogler/Documents/python_files_sublimetext3/practice] [path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/aria2/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands] 

    问题补充

    import pygame 库是正常的

    pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html [Finished in 0.2s] 

    初学 python 不久,不确定还需要补充哪些信息帮忙定位,我会继续补充 自己 Google 了 2 天了还是没解决,希望有好心大佬帮忙,感激不尽

    6 条回复    2020-04-21 11:59:19 +08:00
    leishi1313
        1
    leishi1313  
       2020-04-21 05:59:23 +08:00
    把你的 ‘calendar.py’ 改个名吧
    EricCartmann
        2
    EricCartmann  
       2020-04-21 08:25:09 +08:00 via iPhone
    自己写的 Python 文件名出问题了,Python 导入的时候最先找的是当前工程下的文件,所以在导 calendar 这个自带模块的时候找到你自己写的这个文件了。。以后最好不要用这样的英文名字,建议用拼音(狗头)
    bany
        3
    bany  
       2020-04-21 09:22:53 +08:00
    从 log 上看```"/Users/noogler/Documents/python_files_sublimetext3/practice/calendar.py", line 9```第 9 行报错了,原因是你这个文件中有个 month 变量,刚好你的文件名与导入的包名是一样的(不建议这么取名),发生了冲突,在调用的时候,Python 查找的方式遵循`legb`: local->enclosing(闭包)->global->build-in 。最简单的改法就是把文件改了
    cpluspython
        4
    cpluspython  
    OP
       2020-04-21 11:57:23 +08:00
    @leishi1313 可以了 感谢!
    cpluspython
        5
    cpluspython  
    OP
       2020-04-21 11:58:04 +08:00
    @EricCartmann 明白了 感谢!
    cpluspython
        6
    cpluspython  
    OP
       2020-04-21 11:59:19 +08:00
    @bany 学习了学习了 我再好好整理下 感谢!
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1368 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 61ms UTC 16:42 PVG 00:42 LAX 09:42 JFK 12:42
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86