Python Script Won't Run Via TextMate, OK in IDLE and Eclipse

梦想与她 提交于 2019-12-01 02:11:47
Ned Deily

The problem you are seeing has nothing to do with the Python version. The problem is that TextMate does not try to redirect standard input so, when you are running via the TextMate's Python bundle Run Script command, the Python program sees an immediate end-of-file. As explained here, TextMate used to be fancier about this but the mechanism it used no longer works in OS X 10.6 so the feature was disabled.

One solution is to use the Shift-Command-R Run Script in Terminal command of TextMate's Python bundle. This causes TextMate to open a terminal window and run the script there and you can enter the input there. Unfortunately, while TextMate does respect the shebang line with the normal Command-R Run Script command, it doesn't seem to do so with the Run Script in Terminal command. You can verify that yourself in various ways. Try running this code snippet in TextMate:

#! /usr/local/bin/python3
import sys
print(sys.executable)

To get around that, you can set the TM_PYTHON environment variable in TextMate. See the answer here for more details on how to do that.

Textmate is using the built-in Python, rather than respecting the shebang line. You'd probably have to hack the bundle code to use the right python.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!