ImportError in the console, but import is working in PyCharm

陌路散爱 提交于 2021-02-11 07:44:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!