PyCharm ImportError

时间:2015-12-07 07:28:21

标签: python macos pycharm importerror

Python3.5(和MacOS)的新手,并且已经开始使用PyCharm IDE。我正在使用Download file from web in Python 3中的示例来下载文件,但它在第一个语句中失败了:

import urllib.request 
url = 'http://example.com/'
response = urllib.request.urlopen(url)
data = response.read()      # a `bytes` object
text = data.decode('utf-8')


/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5      /Users/nevd/PycharmProjects/py3/download.py
Traceback (most recent call last):
  File "/Users/nevd/PycharmProjects/py3/download.py", line 4, in <module>
  import urllib.request
  File "/Users/nevd/PycharmProjects/py3/urllib.py", line 9, in <module>
   import urllib.request
ImportError: No module named 'urllib.request'; 'urllib' is not a package

但是,终端的代码工作正常,所以我认为问题是PyCharm配置问题。在PyCharm File>Default Settings>Default Project>Project Interpreter下,项目解释程序是3.5.0但低于我只看到2个包:pip 7.1.2&amp; setuptools 18.2

Mac OS X v10.11.1(El Capitan)和PyCharm Community 5.0.1

1 个答案:

答案 0 :(得分:2)

除了将文件从urllib.py重命名为其他内容之外,您无需执行任何操作。在这种情况下,您正在为要添加到文件中的库包覆盖。

  

重命名您的文件