已解决】Sublime中运行带input或raw_input的Python代码出错:EOFError: EOF when reading a line(转)
【问题】
在折腾:
【已解决】Sublime Text 2中运行Python程序出错:The system cannot find the file specified
的过程中,虽然解决了找不到python.exe的问题,但是又出现下面这个错误:
|
Demo print in Sublime Text 2Traceback (most recent call last): |
截图:

【解决过程】
1.此处出错也很明显,就是Sublime中,运行python代码时,暂不支持输入参数,所以不支持Python中的input或raw_input,所处出现此错误。
2.所以接着就去想办法,添加对应的输入参数的支持。
3.参考:
【教程】把Sublime Text 2用作Python的IDE去实现Python的开发
中
Sublime Text 2 console input
提到的
SublimeREPL
4.参考其中提到的,先去:
http://wbond.net/sublime_packages/package_control
安装对应的包管理器。
快捷键:Ctrl+`,打开Sublime的console:

Ctrl+V,粘贴下面代码:
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')
到console中,然后按Enter键,稍等一下,此包管理器即安装完成:

然后重启sublime。
5.然后去
Preferences -> Package Control

选择Install Package

再选择sublimerepl:

然后状态栏中就显示正在安装SublimeRepl:

很快就安装完成了。
6.然后再去配置SublimeRepl:
Preferences -> Package Settings -> SublimeREPL -> Settings – User

暂时看到的配置是空的:

暂时不需要添加,等后续需要再添加相应的配置。
7.参考,
http://sublimerepl.readthedocs.org/en/latest/
先确保当前打开的Python文件,然后再:
Tools -> SublimeREPL ->Python -> python

结果却发现,很悲催的是,其只是,另外单独打开了一个Python的Shell窗口:

而不是我们所希望的,代替sublime的python。
所以,结果就是,根本没法通过SublimeREPL提供一个供Python代码输入参数的cmd环境。
8.再去自己折腾试试。
先试试:
Preferences -> Browser Packages

然后可以找到很多语言的配置,包括了Python:

可以看到对应的build的配置文件:
C:\Users\CLi\AppData\Roaming\Sublime Text 2\Packages\Python\Python.sublime-build

打开后,内容如下:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}

可以看到,其是调用python,然后加上-u参数。
所以,先去cmd中,看看本身Python支持哪些参数:
|
Microsoft Windows [Version 6.1.7601] C:\Users\CLi>python -h Options and arguments (and corresponding environment variables): -B : don’t write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x -c cmd : program passed in as string (terminates option list) -d : debug output from parser; also PYTHONDEBUG=x -E : ignore PYTHON* environment variables (such as PYTHONPATH) -h : print this help message and exit (also –help) -i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x -m mod : run library module as a script (terminates option list) -O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x -OO : remove doc-strings in addition to the -O optimizations -R : use a pseudo-random salt to make hash() values of various types be unpredictable between separate invocations of the interpreter, as a defense against denial-of-service attacks -Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew -s : don’t add user site directory to sys.path; also PYTHONNOUSERSITE -S : don’t imply ‘import site’ on initialization -t : issue warnings about inconsistent tab usage (-tt: issue errors) -u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x see man page for details on internal buffering relating to ‘-u’ -v : verbose (trace import statements); also PYTHONVERBOSE=x can be supplied multiple times to increase verbosity -V : print the Python version number and exit (also –version) -W arg : warning control; arg is action:message:category:module:lineno also PYTHONWARNINGS=arg -x : skip first line of source, allowing use of non-Unix forms of #!cmd -3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix file : program read from script file - : program read from stdin (default; interactive mode if a tty) arg …: arguments passed to program in sys.argv[1:] Other environment variables: PYTHONPATH : ‘;’-separated list of directories prefixed to the default module search path. The result is sys.path. PYTHONHOME : alternate <prefix> directory (or <prefix>;<exec_prefix>). The default module search path uses <prefix>\lib. PYTHONCASEOK : ignore case in ‘import’ statements (Windows). PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr. PYTHONHASHSEED: if this variable is set to ‘random’, the effect is the same as specifying the -R option: a random value is used to seed the hashes of str, bytes and datetime objects. It can also be set to an integer in the range [0,4294967295] to get hash values with a predictable seed. C:\Users\CLi> |
所以,就去改为别的参数,去试试效果。
9.(1)改为:
{
"cmd": ["python", "-u -i", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
结果再去运行Python代码,结果是:
|
Unknown option: – Unknown option: – usage: python [option] … [-c cmd | -m mod | file | -] [arg] … Try `python -h’ for more information. [Finished in 0.1s with exit code 2] |
(2)再改为:
{
"cmd": ["python", "-u", "$file", "-i'"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
结果是和之前同样的错误:EOFError: EOF when reading a line
(3)改为pythonw:
{
"cmd": ["pythonw", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
结果是,没变化,觉得有问题。所以重启sublime,然后再运行,结果是类似的错误
|
Traceback (most recent call last):Demo print in Sublime Text 2 Now in sublime text 2, please input parameter: sublimeText2IdeDemo(); inputVal = raw_input("Now in sublime text 2, please input parameter:"); EOFError: EOF when reading a line [Finished in 0.8s with exit code 1] |
10.实在没辙了。
只能找别的办法了。
参考:
Python 3.1 and Sublime Text 2 error
知道了,官网已经有人讨论了此问题了:
但是还是官网没有真正解决。
还是这人弄了个插件支持输入:
https://github.com/eric-wieser/build-with-input
但是不能同时支持输出和输入,这个很恼人,所以也懒得去试了。
11.最后,是参考:
Sublime Text 2最为python开发的ide还不错
(先去把Python配置恢复为最原始的:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
)
去:
(1)打开当前python文件
(2)然后
Tools -> Command Palette

(3)SublimeREPL Python RUN current file

(4)就会打开新窗口,显示python的shell,可以供你输入参数了:

(5)接着就可以输入参数,再按Enter,即可输入:

如上的运行当前Python文件,也可以通过:
Tools -> SublimeREPL -> Python -> RUN current file

12.另外,关于窗口显示,设置为上下显示,即2 row的形式,更方便我们调试代码:
View -> Layout -> Rows: 2

然后再去运行:
Tools -> SublimeREPL -> Python -> RUN current file
好像还是默认同行显示:

但是我们可以手动拖动到下面那栏:

就可以上下显示了:

然后接着就可以正常调试了:

13.另外,又试了试,
第二次,再去
Tools -> SublimeREPL -> Python -> RUN current file
运行Python代码时,结果又出现其他错误:
|
D:\tmp\dev_install_root\Python27_x64\python.EXE: can’t open file ‘$file_basename’: [Errno 2] No such file or directory ***Repl Closed*** |

所以,真心的,不好用。
【总结】
对于别的很多IDE都集成很好的Python的shell环境,Sublime竟然不支持,而且即使使用上述SublimeREPL去间接支持,都还是很不好用。
还不能同时支持输入和输出,所以,用Sublime来开始Python的话,真的不是好的选择。
还是用
【整理】各种Python的IDE(集成开发环境)的总结和对比
中提到的,各种其他IDE,比如有Eclipse+PyDev,Ulipad等等,比较好用。
当然,Sublime的一个比较大的优点是,界面好看。
已解决】Sublime中运行带input或raw_input的Python代码出错:EOFError: EOF when reading a line(转)的更多相关文章
- sublime text 2 运行 python时返回EOFError: EOF when reading a line错误
其主要原因是sublime text 2中python没有与 stdin(标准输入)连接所致,解决方法也很简单,那就是安装sublimeREPL插件,然后 Tools->sublimerepl- ...
- sublimetext 2 编译文件带input时 提示 EOFError: EOF when reading a line
昨天在网下下载了个什么sublimetxt 2 的破解版,然后让我折腾了半天,没错 ,就是因为这个 EOFError: EOF when reading a line错误让我搞的半死.怨自己,贪图中文 ...
- 当Sublime Text 2 遇到 EOFError: EOF when reading a line
重新用Sublime Text, command+B运行一小段python程序时遇到 EOFError: EOF when reading a line 似曾相识哪里见过,但是想不起来该如何解决了 S ...
- sublimetext2 中运行Python提示EOFError: EOF when reading a line
解决方法:一.安装sublimeREPL 打开sublimeText2按CTRL+SHIFT+P,英文版输入:install后选择Package Control: Install Package ...
- 解决eclipse中自带的maven搜索不到非本地第三方包问题
解决eclipse中自带的maven搜索不到非本地第三方包问题 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近使用eclipse中的maven插件时发现,在pom.xml文件中添加第 ...
- 解决iOS中tabBarItem图片默认颜色的问题(指定代码渲染模式为以原样模式的方式显示出来)
解决iOS中tabBarItem图片默认颜色的问题(指定代码渲染模式为以原样模式的方式显示出来) 解决办法:指定图片的渲染模式(imageWithRenderingMode为:UIImageRende ...
- Sublime2编译Python程序EOFError:EOF when reading a line解决方法【转】
在Sublime2中编译运行Python文件时,如果代码中包含用户输入的函数时(eg. raw_input()),Ctrl+b编译运行之后会提示以下错误: 解决方法:安装SublimeREPL打开Su ...
- 解决sublime text3运行PyQt5代码不能显示窗口的问题
如题,在sublime中写了GUI代码,Ctrl+B能运行,但是就是不能显示窗口. 解决办法: 找到路径C:\Users\superlee\AppData\Roaming\Sublime Text ...
- [工具] 解决sublime text运行javascript console无输出问题
1.使用nodeJS在sublime text 运行javascript 下载安装nodeJS 在sublime text新建build system:tools->build system-& ...
随机推荐
- 数字图像去噪典型算法及matlab实现
原文地址http://jncumter.blog.51cto.com/812546/243961 图像去噪是数字图像处理中的重要环节和步骤.去噪效果的好坏直接影响到后续的图像处理工作如图像分割.边 ...
- [POJ] #1005# I Think I Need a Houseboat : 浮点数运算
一. 题目 I Think I Need a Houseboat Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 97512 ...
- 如何在Fedora 22上面配置Apache的Docker容器
在这篇文章中,我们将会学习关于Docker的一些知识,如何使用Docker部署Apache httpd服务,并且共享到Docker Hub上面去.首先,我们学习怎样拉取和使用Docker Hub里面的 ...
- c++一些问题总结
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...
- HD4505小Q系列故事——电梯里的爱情
Problem Description 细心的同事发现,小Q最近喜欢乘电梯上上下下,究其原因,也许只有小Q自己知道:在电梯里经常可以遇到他心中的女神HR. 电梯其实是个很暧昧的地方,只有在电梯里,小Q ...
- JS制作的简单的三级及联
前台: <form id="form1" runat="server"> <div> 省 <select id="Pro ...
- php中定义类
<?php class Person{ //定义了一个Person类 public $name; //定义属性name public $age; //定义属性age function __con ...
- css 关于两栏布局,左边固定,右边自适应
好几个星期都没写博客了,最近不忙也不闲,稀里糊涂过了两个星期,之前几个月内天天坚持签到.最近也没签到.哈哈,说正事. 今天做东钿互金平台后台页面,昨天做了一个登录页面,业偶碰到了一个难题.等下也要把它 ...
- 关于 mobile sui a外链 老是出现加载失败的解决办法
mobile sui 框架里面的a本身都绑了了一个ajax方法,ajax只能处理同域,跨域就会出现问题 ,所以mobile sui 中的a如果是外链的话就会出现加载失败的提示,这种明显的bug,让用户 ...
- Js弹出层,弹出框代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...