4

我将不胜感激任何帮助。我使用 Python 3.4.1 并尝试导入 urllib.request 和 urllib.parse。没有成功。我总是收到:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/x/Documents/PROGRAMING and MODELING/Phyton/find cure words/importowanie.py", line 1, in <module>
    import urllib.parse
  File "C:/Users/x/Documents/PROGRAMING and MODELING/Phyton/find cure words\urllib.py", line 1, in <module>
    import urllib.request
ImportError: No module named 'urllib.request'; 'urllib' is not a package

我想问题出在导入上,但我不知道如何解决

4

2 回答 2

10

如果没有实际的代码,我是根据我过去遇到这种错误的经验来猜测的。

我想您正在尝试导入urllib.parse一个名为importowanie.pyin的文件C:/Users/x/Documents/PROGRAMING and MODELING/Phyton/find cure words。当 Python 尝试通过 name 导入模块时urllib,它首先检查您尝试导入的同一文件夹。在您的情况下,它会看到urllib在您尝试导入它的同一文件夹中调用了一个模块。它看到的是该模块内部,而不是“真正的”urllib。由于它在您的内部没有看到任何称为parseurllib的内容,因此会引发错误。这是因为一个名为urllib.pyin的文件C:/Users/x/Documents/PROGRAMING and MODELING/Phyton/find cure words

因此,解决方案是将urllib上述目录中的名称重命名为其他名称,然后重试。

于 2014-06-09T06:53:22.317 回答
-1

我在安装 urllib.parse 时也遇到了麻烦。您可以手动包含对我有用的源:https ://hg.python.org/cpython/file/3.3/Lib/urllib/parse.py

转到源链接,复制源,将其保存为适当的文件名/格式,导入它就可以了。

编辑:错误的链接

于 2016-02-27T22:22:23.033 回答