Python-在控制台中导入 pandas 有效,但在运行脚本时无法导入 [英] Python - Importing pandas in console works but not when running script
问题描述
我已经使用anaconda3/python3.5和pandas一年多了,突然在控制台外运行脚本时,我收到了pandas的导入错误,尤其是依赖项email.parser.我没有找到名为"email.parser"的模块;"email"不是软件包.但是,在控制台中导入可以正常工作.我没有在任何其他环境中运行
I've been working with anaconda3/python3.5 and pandas for over a year and all of sudden when I run my script outside the console, I get a import error for pandas particularly the dependency email.parser. I get No module named 'email.parser';'email' is not a package. However importing in the console works fine. I'm not running any other environment
推荐答案
我今天也遇到了同样的问题.您缺少特定的路径.发现如果启动python解释器并执行import os
,则可以执行os.environ
.您会注意到PATH变量中设置了多个路径.将整个PATH行复制/粘贴到脚本中.那对我有用.另外,请记住删除字符串单引号(例如').
I also had the same problem today. You're missing a specific path. Found that if you start your python interpreter and do import os
, you can do os.environ
. You'll notice that there are several paths set in the PATH variable. Copy/paste the entire PATH line into your script. That worked for me. Also, remember to remove string single quotes (e.g., ').
这篇关于Python-在控制台中导入 pandas 有效,但在运行脚本时无法导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!