2016-03-15 61 views
1

工作,我有其中进口请求模块这样的PROGRAMM:导入错误控制台,但进口在PyCharm

import urllib 
from urllib import request 
... 

的PROGRAMM在PyCharm-IDE运行良好。 但是,当我在Linux操作系统Ubuntu控制台运行相同的代码,我得到的错误:

ImportError: cannot import name request 

有我的路出了问题?我应该提供更多信息来解决这个问题吗?根据ImportError on console but not in PyCharm PyCharm正在设置工作目录。

但是,当我在此工作目录添加到我的脚本,如:

import sys 
sys.path.append('/home/kame/Dropbox/myCode/python/scripts/') 

我仍然得到同样的错误。

+0

可能是PyCharm向python路径添加一些路径的情况。做'print('\ n'.join(sys.path))'来找出。 – Muctadir

回答

1

urllib.request module是在Python 3.x中引入的。

我怀疑PyCharm使用Python 3.x,而在控制台中使用Python 2.x.在控制台中尝试使用Python 3.x。