Mr Ed
Mr Ed

Reputation: 75

PyCharm ImportError

New to Python3.5 (and MacOS) and have begun by using the PyCharm IDE. I'm using an example from Download file from web in Python 3 to download a file, but it fails at the first statement:

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

However the code works OK from Terminal, so I assume the problem is a PyCharm configuration issue. Under PyCharm File>Default Settings>Default Project>Project Interpreter the project interpreter is 3.5.0 but below that I only see 2 Packages: pip 7.1.2 & setuptools 18.2.

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

Upvotes: 0

Views: 692

Answers (1)

Prashant Shukla
Prashant Shukla

Reputation: 762

You don't have to do anything just rename your file from urllib.py to something else in this case you are overshadowing your library package which you are adding to the file.

Rename your file

Upvotes: 2

Related Questions