简体   繁体   中英

Sublime uses Python 3, SublimeREPL uses Python 2.7. Huh?

Using MacOs 10.13. When I launch the following code in Sublime 3:

import platform
print(platform.python_version())

the result is 3.6.3, which is great.

When I launch the same code in SublimeREPL, the result is 2.7.10

So,I think that SublimeREPL is using Python 2.7 and Sublime is using Python 3.6 My question: how do I make REPL use Python 3? Or am I completely misinterpreting something? My idea is that Sublime 3 comes with its own version of Python 3, and REPL comes with its own version of 2.7... might this be true?

Sublime does indeed come with it's own version of Python, although it's Python 3.3.6, which you can see by selecting View > Console from the menu and entering the following code (or the code in your question, although in this case that provides slightly less detailed information):

import sys
print(sys.version)

That said, this version of Python is embedded in Sublime directly and is used only for plugins that you or other developers create for Sublime (much default functionality in Sublime is also defined in Python).

As such, it's not accessible to outside code at all, so there's no way to use it to run your own scripts for example. For that you need to separately install Python on your machine.

Linux and MacOS generally come with a version of Python installed, but Windows does not. So on Windows there's an extra step if you want to run external Python programs, whereas on the other OS's you can generally get going quickly.

If you're on MacOS, that's quite likely Python version 2.7 since that's the version of Python that comes pre-installed on that OS (at least as far as MacOS 10.10 at any rate). If you're on Linux, this might be a version of Python 2 or it might be Python 3, depending on your distribution.

Since the two versions are not fully compatible with each other, you may find that python executes version 2 and python3 executes version 3, depending on which version(s) you have installed.

The Python.sublime-build that ships with Sublime in the Python package, which is used by Tools > Build to build/run Python programs tries to execute python to run external code, which in most cases is going to be Python 2.

I don't use the REPL package, but I would hazard a guess that by default it's configured to execute python as well, and so it's picking up your installed version of Python 2, which is why you're seeing that.

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