简体   繁体   中英

Python 3 is not working with Sublime Text 2

I have been using Sublime Text 2 for over a year and recently started using it for Python. Sublime has a built it build for Python which I tried using (the built in one is for 2.7.3 or something 2.XI believe). I am using Python 3.3.0. I already edited the sublime-build file and changed it to:

{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}

As suggested on stackoverflow on another thread. I tried restarting sublime and trying to run my code:

x = input("Name: ")
print("Welcome " + x)
input()

But at the console at the bottom I get the following error when I run with build (Ctrl+B):

Name: Traceback (most recent call last):
File "/home/andrew/grive/Documents/RandomProjects/PythonStuff/HelloWorld.py", line 32,      
in <module>
x = input("Name: ")
EOFError: EOF when reading a line
[Finished in 0.1s with exit code 1]

Also, I tried to bypass the built in build function by just using SublimeREPL and the Python functions in that, but they also detect my Python build to be 2.7.3 thus not compiling my 3.3.0 code. Note that I do have Python 3 installed, I am using Ubuntu and when I type "python3" in the terminal Python is launched in the terminal with the correct version.

So I have two questions:

Why is my python3.sublime-build not working and how can I fix it?

And since I am a linux noob, I am having trouble accessing the build files. I got to them once but I forgot how now. They are in /home/~.config/sublime-text-2/ etc etc etc.

I cannot see the .config file, for bonus points could you explain how this works?

Your problem is that the sublimetext builds cannot take user input - there is no input stream connected. Your Python version is irrelevant.

However, it's possible to write a plugin to take input!


As for the config files, just use the "preferences -> browse packages" menu item.

I found that the OP solution of editing the 'Python.sublime-build' file from 'python' to 'python3' functions.

I know this because the OP's solution helped me when I had the same problem, and the proof is in the following line:

import sys
print(sys.platform)

The entire practice code:

import sys
print(sys.platform)
print(2 ** 100)
x = 'Spam!'
print(x * 8)
input('Press ENTER to exit...')

With Python 2.7 the return is 'linux2' (for me). With Python 3.3 the return is 'linux'. This was first detected by me using PVM. When I did 'Build' in Sublime 2, 'linux2' was the output; using the OP's method changed the output to 'linux', so I think that is the correct thing to do (easiest anyway).

Build output with Python:

linux2
1267650600228229401496703205376
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
Press ENTER to exit...Traceback (most recent call last):
  File "/home/sick/Python/script1.py", line 6, in <module>
    input('Press ENTER to exit...')
EOFError: EOF when reading a line
[Finished in 0.0s with exit code 1]

Build output with Python3:

linux
1267650600228229401496703205376
Spam!Spam!Spam!Spam!Spam!Spam!Spam!Spam!
Press ENTER to exit...Traceback (most recent call last):
  File "/home/sick/Python/script1.py", line 6, in <module>
    input('Press ENTER to exit...')
EOFError: EOF when reading a line
[Finished in 0.1s with exit code 1]

There is no program error; it gives an error because the program is expecting user input (as far as I know, but I'm only on chapter 4).

I've had just the same problem and I could do that only when I started this program using the terminal:

 cd WayToFile
 python FileName

Everything is done. Perhaps it's how it must be working in all Python versions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM