Can't run python on powershell - python

When I type python in PowerShell I get an error like:
Program 'python' failed to execute: The system cannot find the file specified
At line:1 char:11
+ python.exe <<<< .
At line:1 char:1
+ <<<< python.exe
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
I have added C:\Python27 and its sub directories to PATH. I can run it by typing python.exe. Can run scripts the same way.
I installed Python 2.7.11 64 bit.

The only way I can reproduce your error is if I replace my python.exe file with a new empty text file named python.exe.
First Steps
I notice you mentioned that you added C:\Python27 and all subdirectories to your PATH. I would first suggest to remove all the subdirectories (just leaving the parent directory) from your path. Make sure you restart Powershell after making this change to pull in the new values. Then test it to see whether this has resolved the issue.
Alternative solution
The other possibility is that somewhere on your path you have either a corrupted python.exe or some other cmdlet, function or script file that is shadowing your python installation. You could try running from within powershell:
Get-Command python | Select-Object -ExpandProperty Definition
to see what powershell is actually referencing.* If the only value returned is C:\Python27\python.exe then I would probably suggest a reinstall.
Notes:
[*] - Taken from https://stackoverflow.com/a/16949127/1468125

I ran into this problem recently. To fix it, I had to edit the PATH environment variable to ensure my installed location of Python 3 came before C:\cygwin64\bin, which has a softlink of python to an older version.
Technically one could also launch the Cygwin install utility and remove the older python to fix it as well.
However all I did was to right click on the My Computer icon, select properties, then clicked on Advanced systems settings in order to open the Windows System Properties dialog. From there I selected the Environment Variables button. Then I saw, again in my case, that C:\cygwin64\bin was listed in the PATH environment variable twice, once in the user variables section and also once in the System variables section. I re-ordered Python38 to be first in my user variables PATH environment and deleted the C:\cygwin64\bin entry from the System variables PATH environment. Then clicked OK and opened a new Terminal in VS code, and all is good.

Related

Cannot run pipenv after successfully installing it

I know this has been asked before and I reviewed the previous posts, but none of those solved my issue.
I'm new to programming so I may get the terminology mixed up but I will try to explain in as much detail as I can.
I am running Python 3.8 on Visual Studio Code. I installed pipenv successfully:
python -m pip install pipenv
Then I try to actually use it and get this error:
pipenv shell --python 3.8
pipenv : The term 'pipenv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ pipenv shell --python 3.8
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (pipenv:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
During installation I got this warning:
WARNING: The script f2py.exe is installed in 'C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
However, I don't actually know how to do this or even if I should, because I get this warning with every package I install but it works fine anyway.
I am following this tutorial:
Video Tutorial
and the guy specifically says to run the pipenv commands in the directory where our project is, which I am doing and I get this error. Nevertheless I tried to cd to the directory where the pipenv installed and same error.
I am on Win 10 btw. What am I doing wrong?
You may need to add pipenv to you path variable. Check out the note section in the docs. It actually describes how to get the right location to add on Windows:
On Windows you can find the user base binary directory by running
python -m site --user-site and replacing site-packages with Scripts.
For example, this could return
C:\Users\Username\AppData\Roaming\Python36\site-packages so you would
need to set your PATH to include
C:\Users\Username\AppData\Roaming\Python36\Scripts. You can set your
user PATH permanently in the Control Panel. You may need to log out
for the PATH changes to take effect.
That should get it recognized by your terminal.
The last sentence of that reminds me (it's been a while since I used Windows) -- have you tried to restart or logout? I'm not sure if that's necessary to be honest but I know sometimes it is.
Long story short (and only since you mentioned that you are new to programming) -- the "path" lists all of the locations that are accessible to execute from. You can add to it if you want to be able to execute new programs, like pipenv.
This is what solved the issue for me (Windows 10):
I added the correct Scripts folder of the Python version I am actually running. In my case this was C:\python\Scripts. I added that in Control Panel - search "environment" - Edit environment variables (both for my account and system-wide - did it on both places just to be sure, maybe redundant) - Path - Edit - added the path and now the issue is solved. Thank you!!! –

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.

command line not recognizing python despite it being on my computer

I tried the answer to when this was asked previously and it didn't work, so I'm asking here.
I'm very new to both windows and python, and am trying to run python from my (Windows 10) command line so that I can use pip to install a package (SpaCy). I'm not entirely sure what I'm doing wrong, but after the
C:Users\myname>
typing
C:Users\myname>python
leads to an invalid syntax error, saying:
'python' is not recognized as an internal or external command,
operable program or batch file.
I have python 2.7 installed on my computer, and it works when I use an interpreter such as Rodeo.
I also get the same error when trying to use pip to install SpaCy, although when I try to install pip I get a message that pip is already installed.
Is there some basic knowledge I'm just missing?
When you installed Python, there would have been a tick box that wanted to know if you would like the Python Path adding to the Environment variables. As you didn't select this, your Windows Path doesn't include the folder where the Python executable lives.
To fix this, rerun the installer and modify your install, it should pop up the screen with the tick boxes on, select the one mentioned above and the job should be done.
This is how it works with the Python3 installer, anyhow and I assume that 2.7 will use the same basic model.
You may need to add the newly installed location of python to your path variable.
Control Panel > System > Advanced system settings > Environment variables
Find "Path" and edit.
Append a semicolon ';' and add the full path to your python install location.
To try your new path, you may need to start up another command line cmd.exe to pick up the new PATH.
You need to add python.exe to your Path:
Locate where Python is installed. It's usually located at:
C:\Users\<username>\AppData\Local\Programs\Python\<version>
Now you need to add this directory to your path. To do that press Windows Key, search for 'Environment Variables' and click on 'Edit the System Environment Variables'.
Then 'Environment Variables...'
Click on 'Path' variable and hit 'Edit...'
Then, 'New'...
Put the directory where your Python.exe is installed and hit okay,
Restart your command prompt and try again.
You need to add python installation path to your environment variable.
Click search icon on windows task bar--> type "environment variable" Edit environment variable will pop (System or User)--> add path to python installation till bin to "Path" variable.

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

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.

Add “python2” path to command line on Windows 7

I've been trying to add the python2 path to command line on Windows 7.
I have tried to do it this way:
C:\>set python2 = C:\Python27\python.exe
But cmd told me that:
'python2' is not recognized as an internal or external command.
So how can I add python2 path to command line on Windows 7?
Thanks.
This answer copied from my own answer, and customized to this question.
Try following command.
set path=%path%;c:\python27
PATH is set only for the cmd.exe in which you run the above command.
To permanently set PATH:
Right click My computer in the desktop.
Click Advanced System Settings on the left.
Click Environmental Variable.
Add or Update PATH variable:
If it does not exist, create one, and set value as C:\python27
If it exist, append ;C:\Python27 to existing value.
Restart cmd.exe. (PATH will not change for already launched cmd.exe)
UPDATE
If you want to use python2, copy the executable.
CD C:\python27
COPY python.exe python2.exe
Had the same problem and fixed it...
I have C:\Python27, which i have added to my environment variables which gave me access to "python" though the CMD.. but for installing node-sass though npm, which was my problem, it continues to say that "python2" is not found. A friend the told me i could just rename name executable, which i didn't belive, but it worked :-)
The rename was from:
C:\Python27\python.exe > C:\Python27\python2.exe
It works for me, even though it find it weird just renaming a file.. but then, i am not hardcore in the windows CMD.
I don't know whether it can be switched or not while keeping both python2 and python3.
But while working with python2 you can remove the "python3 path" from the PATH.
Cause By default in windows python3 is selected if both are installed.
So you can try this to use python2. then when necessary again add the "python3 path " to the PATH
although I add Python to path variable, it appeared further, I tried with Thor A. Pedersen's answer it worked, I found another way without rename python.exe to python2.exe, just update your node config as bellow. It worked for me.
npm config set python python2.7
or
npm config set python python

Categories

Resources