0

I'm attempting to build my hello_world.py code according to the instructions in Python Crash Course 2nd edition by Eric Matthes. The process seems clear enough, so while I'm trying to follow the directions precisely, I'm obviously missing something along the way. I have new installs of Python 3.9.7 and Sublime as of 7SEP2021. In Powershell, this first basic command works just fine:

PS C:\Users\dtkee\Desktop> python

Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello Python interpreter!")
Hello Python interpreter!
>>> 

Per the book, I didn't have to configure Sublime since there was no instance of Python2 on my system. However, when I create folder "python_work" and place file "hello_world.py" within, the build results I receive seem off:

[WinError 2] The system cannot find the file specified [cmd: ['py', '-u', 'C:\Users\dtkee\Desktop\Python Crash Course\python_work\hello_world.py']] [dir: C:\Users\dtkee\Desktop\Python Crash Course\python_work] [path: C:\Program Files (x86)\VMware\VMware Workstation\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\Python37\Scripts;C:\Program Files\Python37;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files\PuTTY;C:\Users\dtkee\AppData\Local\Microsoft\WindowsApps;C:\Users\dtkee\Desktop\PenTest Tools\Ncrack;;C:\Program Files\JetBrains\IntelliJ IDEA Educational Edition 2020.2\bin;;C:\Program Files (x86)\Nmap] [Finished]

I thought I had followed the book's instructions exactly; I didn't make any changes to the default locations or settings. I've deleted the file and recreated it a few times, but I continue to receive the same results. "File not found" "Invalid syntax" "hello_world not defined".

Even though I can see the file in the directory, something is making Sublime think otherwise. Any insight or recommendations would be appreciated!

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • How did you install Python? – MattDMo Sep 08 '21 at 18:40
  • It looks like your build command is using `py` instead of `python`. What happens if you enter `py` in a terminal instead of `python`? If `py` is not recognized, try making a build system with the command `python` and see if that helps? – japhyr Sep 10 '21 at 03:45
  • @MattDMo I installed Python through the Microsoft Store. Should I remove that install and go another route? – wo_wen_27518 Sep 10 '21 at 17:18
  • @japhyr In Sublime, when I go to Tools>Build with...>Python3, this appears to build successfully. Are you aware of any reason why the default Build command wouldn't work when Python3 is the only install on my device? – wo_wen_27518 Sep 10 '21 at 17:20

1 Answers1

0

[WinError 2] The system cannot find the file specified

The above error is specifically referring to the executable that Sublime is trying to run. It is looking for py.exe somewhere in your path. py.exe is a launcher that looks for the most recently installed version of python.exe to run. It is not found because it is NOT bundled with the installation from the Microsoft Store.

To solve, it seems like the easiest routes would be a) configure Sublime to run your installed version of python, or b) uninstall Python from your machine, then download it and install from https://python.org. Long-term, you're going to need to learn about virtual environments in Python, and the various tools associated with them.

For more information, and documentation of this issue, see: https://learn.microsoft.com/en-us/windows/python/faqs#what-is-py-exe-

soundstripe
  • 1,454
  • 11
  • 19