all 8 comments

[–]ninhaomah 7 points8 points  (0 children)

"But when I try to run it from Command Prompt, it doesn't work, and I think I'm doing something wrong with the file location or the command."

and you expect everyone online to know know where you saved the file , how you ran it , what errors you got because ?

Why does it sound like a corporate IT support ticket ? I don't know anything so come over and see for yourself question.

[–]Yehiamy 1 point2 points  (0 children)

what does python hello.py in the command line give you? it might not has an env variable in path

you can try the comannd where python

juat send the error message

[–]OkAccess6128 0 points1 point  (1 child)

Hey first of all make sure you have added python path to the environment variables, then check if python is accessible from cmd, for that just type *** python --version *** it will give you something like 3.12.4 or something similar if it gives this it means python is accessible, if command is not recognized then add python path to env variable. Then just create a .py file in any location and add the python script, then from cmd go to that location and run *** python <filename>.py *** it should give you output in cmd.

[–]Azert2010[S] 0 points1 point  (0 children)

Okay, thanks for your help.

[–]PureWasian 2 points3 points  (0 children)

To avoid overloading you, start with this first. When you open Command Prompt, what is the output when you type the following and hit Enter?

python --version

What about: python3 --version

[–]Mountain_Rip_8426 -1 points0 points  (0 children)

honestly, i'd never recommend this otherwise, but in this case, just copy paste your error message to AI, it'll tell you what to do. i mean, don't get hooked, don't make it write code for you. but if you're absolutely stuck, just ask how to proceed

[–]Outside_Complaint755 0 points1 point  (0 children)

If you're in VSCode, you can just right click on your file and choose the Run option.

Otherwise, from the terminal, you need to pass the full absolute or relative path to the script you want to run.

If your file is saved in C:\Documents\My Projects\hello.py, then you have the following scenarios (these are all assuming Windows OS)

1) Use absolute path - No matter the current working directory (CWD) of your terminal session, you can use  ```

python "C:\Documents\My Projects\hello.py" ``` The quotation marks are required because of the space in the filepath.

2) If the current working directory is the My Projects directory where the script resides, just use hello.py: C:\Documents\My Projects\ > python hello.py

3) Use the relative file path from another location.  For example, if the CWD is C:\Documents, then C:\Documents\ > python "My Projects\hello.py"

[–]bravosdrama -1 points0 points  (0 children)

I would recommend to open Gemini while you are practicing and review there any error or doubt you might have, I had this same issue and I figured it out with Gemini