【问题】

在折腾:

【已解决】Sublime Text 2中运行Python程序出错:The system cannot find the file specified

的过程中,虽然解决了找不到python.exe的问题,但是又出现下面这个错误:

Demo print in Sublime Text 2Traceback (most recent call last):
Now in sublime text 2, please input parameter:

  File
"D:\tmp\tmp_dev_root\python\tutorial_summary\sublime_text_2_ide\sublime_text_2_ide.py",
line 26, in <module>

    sublimeText2IdeDemo();

  File
"D:\tmp\tmp_dev_root\python\tutorial_summary\sublime_text_2_ide\sublime_text_2_ide.py",
line 22, in sublimeText2IdeDemo

    inputVal = raw_input("Now in sublime text 2, please input parameter:");

EOFError: EOF when reading a line

[Finished in 0.1s with exit code 1]

截图:

【解决过程】

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]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\CLi>python -h

usage: python [option] … [-c cmd | -m mod | file | -] [arg] …

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:

PYTHONSTARTUP: file executed on interactive startup (no default)

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: –

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
  File
"D:\tmp\tmp_dev_root\python\tutorial_summary\sublime_text_2_ide\sublime_text_2_ide.py",
line 26, in <module>

Now in sublime text 2, please input parameter:    sublimeText2IdeDemo();

  File
"D:\tmp\tmp_dev_root\python\tutorial_summary\sublime_text_2_ide\sublime_text_2_ide.py",
line 22, in 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

知道了,官网已经有人讨论了此问题了:

Strange is this a bug?

但是还是官网没有真正解决。

还是这人弄了个插件支持输入:

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(转)的更多相关文章

  1. sublime text 2 运行 python时返回EOFError: EOF when reading a line错误

    其主要原因是sublime text 2中python没有与 stdin(标准输入)连接所致,解决方法也很简单,那就是安装sublimeREPL插件,然后 Tools->sublimerepl- ...

  2. sublimetext 2 编译文件带input时 提示 EOFError: EOF when reading a line

    昨天在网下下载了个什么sublimetxt 2 的破解版,然后让我折腾了半天,没错 ,就是因为这个 EOFError: EOF when reading a line错误让我搞的半死.怨自己,贪图中文 ...

  3. 当Sublime Text 2 遇到 EOFError: EOF when reading a line

    重新用Sublime Text, command+B运行一小段python程序时遇到 EOFError: EOF when reading a line 似曾相识哪里见过,但是想不起来该如何解决了 S ...

  4. sublimetext2 中运行Python提示EOFError: EOF when reading a line

    解决方法:一.安装sublimeREPL    打开sublimeText2按CTRL+SHIFT+P,英文版输入:install后选择Package Control: Install Package ...

  5. 解决eclipse中自带的maven搜索不到非本地第三方包问题

     解决eclipse中自带的maven搜索不到非本地第三方包问题   版权声明:本文为博主原创文章,未经博主允许不得转载. 最近使用eclipse中的maven插件时发现,在pom.xml文件中添加第 ...

  6. 解决iOS中tabBarItem图片默认颜色的问题(指定代码渲染模式为以原样模式的方式显示出来)

    解决iOS中tabBarItem图片默认颜色的问题(指定代码渲染模式为以原样模式的方式显示出来) 解决办法:指定图片的渲染模式(imageWithRenderingMode为:UIImageRende ...

  7. Sublime2编译Python程序EOFError:EOF when reading a line解决方法【转】

    在Sublime2中编译运行Python文件时,如果代码中包含用户输入的函数时(eg. raw_input()),Ctrl+b编译运行之后会提示以下错误: 解决方法:安装SublimeREPL打开Su ...

  8. 解决sublime text3运行PyQt5代码不能显示窗口的问题

    如题,在sublime中写了GUI代码,Ctrl+B能运行,但是就是不能显示窗口. 解决办法:  找到路径C:\Users\superlee\AppData\Roaming\Sublime Text ...

  9. [工具] 解决sublime text运行javascript console无输出问题

    1.使用nodeJS在sublime text 运行javascript 下载安装nodeJS 在sublime text新建build system:tools->build system-& ...

随机推荐

  1. JavaEE5 Tutorial_Jsp,EL

      Jsp的各种元素在转化为servlet时处理是不一样的:指令,控制web容器如何处理页面脚本,被插入到生成的servlet里EL表达式,作为参数传递到解析器get/set Property,变成方 ...

  2. 基于MapReduce的关系代数运算(1)

    1.选择运算 Map函数:对R中的每个元组t,检测它是否满足条件C,如果满足,则产生一个键值对(t,t) Reduce函数:直接将每个键值对传递到输出即可 2.投影运算 Map函数:对R中的每个元组t ...

  3. 转】Mahout分步式程序开发 聚类Kmeans

    原博文出自于: http://blog.fens.me/hadoop-mahout-kmeans/ 感谢! Mahout分步式程序开发 聚类Kmeans Hadoop家族系列文章,主要介绍Hadoop ...

  4. webrtc--AudioProcessing的使用

    1.AudioProcessing的实例化和配置: AudioProcessing* apm = AudioProcessing::Create(0); apm->level_estimator ...

  5. HDU 1712 ACboy needs your help (分组背包模版题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 有n门课,和m天时间.每门课上不同的天数有不同的价值,但是上过这门课后不能再上了,求m天里的最大 ...

  6. UVa 1312 Cricket Field (枚举+离散化)

    题意:在w*h的图上有n个点,要求找出一个正方形面积最大,且没有点落在该正方形内部. 析:枚举所有的y坐标,去查找最大矩形,不断更新. 代码如下: #include <cstdio> #i ...

  7. drop,truncate与delete的区别

    注意:这里说的delete是指不带where子句的delete语句 相同点 truncate和不带where子句的delete, 以及drop都会删除表内的数据 不同点: 1. truncate和 d ...

  8. ASP.NET MVC 修改视图的默认路径(MVC2,MVC3)

    ASP.NET MVC2 修改视图的默认路径 步骤:1.编写继承自WebFormViewEngine的类,重写视图路径 2.在Application_Start()中添加语句: ViewEngines ...

  9. 第四章TPLINK 703n 重要恢复方法,非TTL串口连接

    途中有一次为了试图能够在703N上挂载普通usb(可用空间只有2M多点),卸载了不少系统软件,甚至把UCI给卸载了,导致系统起来后没有SSH服务,只有DNS服务,几乎变砖.百般无奈下,终于找到有高人提 ...

  10. js中有关滑动问题的一些理解

    在做导航栏的时候,肯定会用到点击滑动的,但不知道大家有没有遇到过这种问题: $(window).animate({ scrollTop: "1000px" }) $(documen ...