问题
I have a programm which imports the request module like this:
import urllib
from urllib import request
...
The programm is running fine in the PyCharm-IDE. But when I run the same code in the console in Linux Ubuntu I get the error:
ImportError: cannot import name request
Is there a problem with my path? Should I provide more information to solve this problem?
According to ImportError on console but not in PyCharm PyCharm is setting the working directory.
But when I add this working directory to my script like:
import sys
sys.path.append('/home/kame/Dropbox/myCode/python/scripts/')
I still get the same error.
回答1:
urllib.request module is introduced in Python 3.x.
I suspect PyCharm is using Python 3.x, while in console you are using Python 2.x. Try using Python 3.x in console.
来源:https://stackoverflow.com/questions/36002884/importerror-in-the-console-but-import-is-working-in-pycharm