Why is the windows cmd not working for me? [duplicate] - python

This question already has answers here:
"python" not recognized as a command
(14 answers)
Closed 3 years ago.
While on windows cmd I am coding
C:/Users/Esteban Oquendo/Desktop/python myexample.py
Why I am getting an error message as
'python' is not recognized as an internal or external command,
operable program or batch file.
What I am doing wrong?

You have to make sure that the python.exe folder is in your system path.

Make sure python is installed at the location
C:/Users/Esteban Oquendo/Desktop/
So, make sure python.exe file is present in the directory. If you are not sure where your python is installed. Try this is your windows command line:
which python
You will see the python location if you have python in your system (and if the python path is set correctly). Like this!

Related

'python' is not recognized as an internal or external command, operable program or batch file When trying to run python code in VS code [duplicate]

This question already has answers here:
'pip' is not recognized as an internal or external command
(39 answers)
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
(23 answers)
Closed 7 months ago.
When I try to run Python code in Vs code this appears in the output I have already tried reinstalling both python and Vs code.Ive alos tried other solutions on stackoverflow and none have worked
If you already installed python on Windows, you need to add Python command in the PATH variable.
The complete path of python.exe can be added by:
Right-click This PC and go to Properties
Click on the Advanced system settings in the menu on the left.
Click on the Environment Variables button o​n the bottom right.
In the System variables section, select the Path variable and click on Edit.
The next screen will show all the directories that are currently a part of the PATH variable. Click on New and enter Python’s install directory. Now you can use python directly from the command prompt without having to write its full path location.
Try executing the command py --version; it will output the version of Python installed on your system.

How would I go about making a Python script into an executable? [duplicate]

This question already has answers here:
Set up Python on Windows to not type "python" in cmd
(4 answers)
How to make python scripts executable on Windows? [duplicate]
(1 answer)
Closed 5 years ago.
I'm reading from a "bookazine" which I purchased from WHSmiths today and its said
during the setup I need to type in these commands into the terminal (or the Command Prompt in my case) in order to make a script without needing to do it manually. One of these commands is chmod +x (file name) but because this is based of Linux or Mac and I am on Windows I am not sure how to make my script executable, how do I?
Thanks in advance.
In the Python documentation there is a small excerpt on this.
On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to make scripts executable from the command prompt as ‘foo.py’. If you’d rather be able to execute the script by simple typing ‘foo’ with no extension you need to add .py to the PATHEXT environment variable.
https://docs.python.org/2/faq/windows.html
Aside from that, like cricket_007 said, you can execute your scripts as
C:\User\YourName> python yourscript.py
You don't have shell scripts on Windows, you have batch or powershell.
If your reading is teaching Unix things, get a virtual machine running (insert popular Linux distribution here).
Regarding python, you just execute python script.py

How to tell, from within a running script, what Python interpreter is running it? [duplicate]

This question already has answers here:
Find full path of the Python interpreter?
(3 answers)
Closed 6 years ago.
I would like to output, in my script, the full path of the Python interpreter running it:
#!/usr/bin/env python
print("{}".format(full_path_of_interpreter_running_this_script)
The script is in the PATH and run as:
script.py
Can I do that? How?
Note: Doing which python or type python in bash does not help me, because I am using pyenv, and pyenv is doing shims magic.
Note: More than identifying the Python executable, I am interested in identifying the virtualenv that is being used, and I thought knowing the full path to the interpreter will help me in this.
This gives the full path to the command that was used to run the script:
import sys
print(sys.executable)

Execute Python in Sublime Text 3 [duplicate]

This question already has an answer here:
How do I run python from Sublime text 3?
(1 answer)
Closed 6 years ago.
How can I execute Python 2.7 code using Sublime Text 3 on Windows 10? When I use the shortcut Ctrl+B it says 'python' is not recognized as an internal or external command, operable program or batch file. I can't edit python.sublime-build because as far as I know it does not exist in Sublime Text 3.
EDIT: I see this question is a duplicate. I did not see the post when I searched up the topic for some reason.
You need to add python to your system path or if you already have there is a chance that
that in C:\Windows there is exe with python icon called "py" rename it to "python" and it should work fine.

Pydoc won't run on command prompt [duplicate]

This question already has answers here:
Pydoc is not working (Windows XP)
(8 answers)
Closed 8 years ago.
I'm working through this "Learn python the Hard Way" book and the book is now saying to run
'pydoc open'
I do this and get the response that pydoc is not an internal or external command etc.
I've trying adding 'C:\Python27\lib\pydoc.py' to PATH and restarting my computer but it still hasn't worked.
Python is probably not in your path. you must add it in your path either by using the GUI or something like this:
set PATH = PATH;/path/to/pydoc/
This is a windows example, but it should not be hard to convert to a *nix version. The export command can be used in that case.

Categories