Trying to access Python through Windows Command Prompt without adding Environment Variable - python

I am trying to access Python through a Windows command prompt, but am at an office and cannot add an Environment Variable. So, I cant follow the advice provided here. Thus, I added a User Environment Variable through User Accounts and use Variable:python and Value: C:\Python33. When I do a Windows Run check on %python% I reach the required Python33 folder. However, when I type python -Version in the command prompt I get the error 'python' is not recognized as an internal or external command, operable program or batch file. I am not sure how to proceed.

Run Python from the command prompt and include the full path to python.exe. For example to get the version:
C:\Python33\python.exe --version
When you run a script you specify the path to the script if you're not in the directory where the script is located. For example, if your script is in C:\scripts and is called my_script.py:
C:\Python33\python.exe C:\scripts\my_script.py

Instead of setting environment variables, you can use the whole path, like Neo wrote e.g.:
C:\Python33\python.exe yourPythonScript.py
Remove any environment variables you have added.

C:\Python33\python.exe pyscript.py should work.

I once Had a similar problem, but i couldnt find any solution, not even adding the path to the python folder was working.
Then I opened Python and clicked in File, then browser path, and I found that I had another folder that contained the real Python folder, not the default one. Maybe it could work for you too.

Related

Python isnt recognized in cmd and i cant use pip

im pretty new to coding and stuff but for whatever reason, python, pip or even doing cd C:\Python38\scripts cmd will just tell me the directory isnt found or that it isnt a command, i did echo %PATH% and it is in there. (this is probably a really simple solution, im not advanced with stuff like this at all)
Open a new CMD with the start menu
go to the location where python is installed.
press on the Path next to Search Bar.
Copy, back to CMD, cd (paste)
This will set the working directory to where python is installed.
You can test now with python command, and check it it works , then the issue is only path related.
Now for checking with Path, You will need to add the complete path to the python.exe the one you just copied into CMD.
For example
C:\Users\George\AppData\Local\Programs\Python\Python39 at this path there will be a python.exe where You can execute with CMD.
If you have an issue with the path and have to update to the new one, Make sure to start a new CMD window to take the effects of the Path update.
You would need to add python in the PATH variable to access python from cmd in windows.
Please see the article at this link Adding python to Path
Post that you would be able to access pip from cmd/ use pip within cmd

can not add python to the path of environment variable

I have the same old problem of python not being recognized and get this error in VS:
[Running] python -u "c:\Users\Keram\Desktop\WEB\index.py"
'python' is not recognized as an internal or external command,
operable program or batch file.
the solution is said to be putting the path of the python file where it is installed in the PATH of the environment.
but I had the same issue with node.js and had to put its path as the environment variable path.
now if I add python's path, I would not have node.js.
what am I supposed to ?
You can set path for node and python both, it doesn't affect anything.
Just go to environment variables, click path, edit, and then add the path of python executable file.
Then just restart/reopen the terminal and check.
I had the issue with python where the name was python3 not the python
Renaming solved that issue too.
Hope it helps.!

I can't get the python commandline program to work. In spite of having set the PATH variable

Quick question regarding the installation of python. I've installed Python 3.7.7 using the Windows 64 bit installer. I also had the installer update the PATH variable for me.
But when doing a quick check with the command-line using the command: "python --version", I'm getting nothing.
Nothing. No error, just an endline.
User Path variable System Path variable command prompt
Edit(1):
By going to the directory with python.exe within the terminal using the command "cd C:\Users\Andrei\AppData\Local\Programs\Python\Python37\" and then using python --version. The command works. I'm receiving the python version 3.7.7 message.
In spite of the path variable pointing to the same folder though, the command still doesn't work when I'm outside it.
A very weird thing I realized is that the command "py" does have some output. Regardless of what directory I'm in.pyOutput
So that command works, while python --version doesn't. In spite of python --version working when I'm within the actual directory of python.exe.
I would assume that while I'm outside the python directory, there's some other executable that the system is accessing first? Regardless, I need all the functionality of python to work as I'm trying to get an external program to work with it and within that program, I'm getting the error that python is not installed. "Download python and add it to the path variable" it still says...
Edit(2)(SOLVED!):
There must've been some other folder within the path that had a python command that was overriding this one, as now it works and all I changed was the position of the folder within the path variable. It previously sat lowest, now it is the first one. And the command always works as intended, regardless of what directory I'm in.previous position new position
First, be sure you added the path to environment variable correctly
for testing, you can open your terminal in your path that you added to the environment variable and run python --version again.
If that not work for you try these solutions:
Close your terminal and open it again
or
try python3 --version instead of python --version
It's probably because you don't have Python installed through the Microsoft Store. You need to write "python" in the cmd and then a Microsoft Store window will pop up and let you download it.

Environmental path to Python not working?

I have Installed Python 3.4 onto a new PC. Python works but I am trying to get pip to work on this. I have made a path for Python which is below.
C:\Python34\python.exe
When i run the below code
C:\Windows\System32>pip install python-docx
'python' is not recognized as an internal or external command,
operable program or batch file.
It seems that you haven't configured your PATH variable correctly. In order to do so:
Hold down the Win key and press Pause.
Click Advanced System Settings.
Click Environment Variables.
Append ;C:\Python34 to the PATH variable.
Restart Command Prompt.
(You may also just run set PYTHONPATH=%PYTHONPATH%;C:\Python34 in the cmd)
Further information is available in The Official Python Installation Guide for Windows.

How to set python enviroment variable on windows

I've downloaded python installer from http://www.python.org/ftp/python/3.1.2/ , this python-3.1.2.msi file, I need to execute some python files? How do I do that? For example in php I'd do php filename.php from console, I do however have python command line but I don't know how to execute those files.
So if I could set ENV variable to directly execute my file(s) if that is possible that would be great.
There is an option in the installer called "Register Extensions" to associate Python files with the interpreter, so double-clicking them or entering filename.py in the console should work.
Apart from that you might want to add C:\Python31 to your PATH variable (right-click on My Computer, choose Settings, choose the Advanced Tab - there you can access the system variables. Better do this as an admin.
If you type python in the Windows command line, what happens? Is the Python interpreter in your PATH yet?
If not, add the Python installation directory there (here's a good guide). Then just do python script.py just like with PHP.
you can just execute
python yourfile.py
Or if the python command don't work you have to give the absolute path to you python installation or add it to windows path

Categories

Resources