简体   繁体   中英

Path Error using Python 3 in Sublime Text

I have a struggle using this editor. I tried it a year ago and after some hair-pulling, ended up leaving it for another platform. I came back today, and I want to fix my problem and go farther than just step one.

I got a picture of my code and will provide the code written out here as well. I will also be providing a picture of the book I am using (Python Crash Course 2nd Edition) with the instructions given to me.

If any more info is needed, or some clarification. Please let me know. I want to get moving past this obstacle.

Picture of my code

print("Hello Python World!")

[WinError 2] The system cannot find the file specified
[cmd: ['python3', '-u', 'C:\\Users\\2\\Desktop\\New folder\\Coding\\python\\python_work\\hello_world.py']]
[dir: C:\Users\2\Desktop\New folder\Coding\python\python_work]
[path: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\2\Desktop\Python\Python310;C:\Users\2\Desktop\Python\Python310\Scripts;C:\Users\2\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\2\AppData\Local\Programs\Python\Python310\;C:\Users\2\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.1\bin;]
[Finished]

Picture of Directions from Book (pg 10)

{
"cmd": ["python3", "-u", "$file"],
}

print("Hello Python World!")

Hello Python World!
[Finished in 0.1s]

Once again, if any clarification or extra detail is needed, just let me know and I will clarify to the best of my ability.

Problem solved

Ended up switching the build system from Python3 to Python and removed the cmd directions from the book. Problem fixed. Big thanks!

The instructions in your book are either out of date or flat out misleading you; I would not recommend following them.

You only need to create your own sublime-build file to execute a Python program as Python version 3 if you're running Sublime Text 3 AND you are on Linux/MacOS.

The Python.sublime-build file that ships with ST3 will execute python.exe by default on Windows which (if you have Python installed and on the PATH ) will work. The version of the file that ships with ST4 executes the py.exe helper on Windows, which is always available on the PATH and will find the right version of Python for you no matter where it's installed (so long as it is in fact installed).

Using the name python3 is required only on Linux and MacOS, for which the name python refers to Python 2 and not Python 3 (and it does not exist on Windows at all, which is the ultimate source of your problem). In ST3 the build always tries to execute python on these platforms, but in ST4 the default is now python3 .

The build as outlined in the book doesn't set up an appropriate selector to allow the build to be auto selected or a file_regex to match errors to allow for error navigation. Perhaps later parts of the book include that; the built in build supports it directly out of the box.

In any case, the most expedient way to test out your code would be to select Python under Tools > Build Systems and then run the build again. Sublime is going to ask you if you want the Python or the Python - Syntax Check build; choose the first one in the list.

The Syntax Check variant only compiles your code but doesn't actually run it, which is almost never want you want.

If that works, you can delete your sublime-build file and change the selected build to Automatic , which will cause Sublime to pick the Python build for you automatically so long as you execute the build while you're editing a Python file.

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