我对python和一般编程非常陌生。我正在尝试同时导入漂亮的汤和请求模块。当我尝试将任何一个模块导入.py文件并通过空闲运行它时,都会出现一个很长很奇怪的错误。
即使我每个人都收到相同的错误,我也找不到其他遇到相同问题的人。任何帮助都非常感谢!
windows 10 python 3.7.0
据我所知,我已经正确设置了python和python脚本的路径。我很确定我已经正确安装了模块,因为当我运行pip Frozen时,我得到了:
arcade==1.3.7
beautifulsoup4==4.7.1
certifi==2019.3.9
chardet==3.0.4
future==0.17.1
h11==0.8.1
html5lib==1.0.1
idna==2.8
lxml==4.3.3
Pillow==5.4.1
pyglet==1.3.2
requests==2.21.0
requests3==0.0.0
six==1.12.0
soupsieve==1.9
urllib3==1.24.1
webencodings==0.5.1
xmlx==2.0.0
我尝试卸载并重新安装python。我最初确实下载了几个不同的版本,所以我想知道这是否可能导致问题。我现在只安装了3.7.0。我已经检查并仔细检查了路径设置是否正确。我尝试过以多种不同的时间和方式安装库。
我的文件已保存并按以下方式运行:
import requests
这是我得到的错误:
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 "C:/Users/NeckR/Desktop/py/ifthisworks.py", line 1, in <module>
import requests
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
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 "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\packages\six.py", line 216, in is_package
return hasattr(self.__get_module(fullname), "__path__")
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\packages\six.py", line 118, in __getattr__
_module = self._resolve()
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Users\NeckR\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:/Users/NeckR/Desktop/py\http.py", line 9
print 'Serving HTTP on port %s ...' % PORT
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Serving HTTP on port %s ...' % PORT)?
答案 0 :(得分:1)
似乎您正在尝试使用python3解释器运行python2脚本。
首先,尝试在括号中使用print
print('Serving HTTP on port %s ...' % PORT)
此外,当某些外部库尝试执行类似import http
之类的操作并且它找到的第一个模块是您的py/http.py
时,您似乎遇到导入问题。尝试将模块重命名为更独特的名称。
此外,您有两个requests
库,其中一个肯定是python2的库。您是如何安装它们的?尝试将它们都卸载并安装适当的一个-适用于python3。
答案 1 :(得分:0)
我解决了这个问题,方法是删除所有可以找到的与python相关的文件,然后重新安装所有文件。经典