【问题】

在折腾:

【已解决】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. Intent传输数据的补充

    发现用intent的putExtra()或者putExtras()传输的都是基本数据类型. 如果要传输自定义数据类型,就要用到其他方法,老罗介绍的大概有3种: 1.  静态变量 2.  全局变量 3. ...

  2. DHCP工作过程详解

    DHCP动态主机配置协议的作用我想作为网管的兄弟们都应该知道了,这里我就不多废话了,今天我要谈的是DHCP的工作过程,了解了工作过程,要排除故障就容易了.   一.DHCP客户机初始化: 1. 寻找D ...

  3. win7 提示"Windows 无法连接到System Event Notification Service服务......"的解决办法

    登录win7系统,突然出现如图1的提示,无线网络中断,不能上网,多次插拔无线网卡问题依然. 图1 解决过程如下: 1.检查网卡硬件状况,在设备管理器中查看网卡现象正常,排除网卡硬件故障. 2.查看服务 ...

  4. proguard 混淆android代码

    官网 http://proguard.sourceforge.net/#manual/examples.html android 2.3后,新建的project默认就有一个project.proper ...

  5. win7的centos虚拟机上搭建mysql5.6服务

    1 安装包下载 mysql5.6下载地址: http://dev.mysql.com/downloads/mysql/ 这里选择linux版本: navicat11破解版的下载地址: http://d ...

  6. NServiceBus教程-持久化配置

    当配置在NServiceBus v5持久性,秩序是非常重要的.最后赢得持久性配置选项.我们看看一些例子. 示例1 在本例中最后一个配置选项将会覆盖前面的所有选项. v5.2 v5.0 编辑 var c ...

  7. 第三百四十七天 how can I 坚持

    下班的时候眼皮就一直在跳,今天意志好消沉,以后还是少说话,多说不宜啊.. 挣脱束缚,无论怎样,对于生命,什么都是次要的,不要想太多. 最近事比较多,应该是累了,睡一觉 应该就好了. 睡觉,晚安.

  8. 解决Ubuntu系统的每次开机重启后,resolv.conf清空的问题

    问题情况描述如下: 普及知识:   /etc/resolv.conf ,其实是一个Link .它其实指向的是 /run/resolvconf/resolv.conf.  Ubuntu 有一个 reso ...

  9. c/c++,输入一个字符 2014-11-20 07:00 30人阅读 评论(0) 收藏

    getch().getche()和getchar()函数     (1) getch()和getche()函数     这两个函数都是从键盘上读入一个字符.其调用格式为:      getch(); ...

  10. android学习笔记(入门篇)

    +号只是当你第一次定义一个资源ID的时候需要, 告诉SDK此资源ID需要被创建出来 对于所有的View默认的权重是0,如果你只设置了一个View的权重大于0,那么这个View将占据除去别的View本身 ...