问题描述
我有一个程序,可以像这样导入请求模块:
I have a programm which imports the request module like this:
import urllib
from urllib import request
...
该程序在PyCharm-IDE中运行良好.但是,当我在Linux Ubuntu的控制台中运行相同的代码时,出现错误:
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?
根据控制台上的导入错误,但在PyCharm中没有 PyCharm是设置工作目录.
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.
推荐答案
我怀疑PyCharm正在使用Python 3.x,而在控制台中您正在使用Python2.x.尝试在控制台中使用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.
这篇关于控制台中的ImportError,但导入在PyCharm中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!