Install Python package, syntax invalid - python

I have the familiar problem of not being able to install a Python package, pyautogui; "syntax invalid", with install highlighted:
pip install pyautogui
The explanations I've read are all the same, that this code is to be entered into one of the IDLE windows and not the other. Well I've tried both and the result is the same, syntax invalid.
This is Python 3.4.3 on Windows 7.

As #TigerhawkT3 said in the comments, you are supposed to install from CMD, not the Python Shell. pip is an executable that downloads packages.
As the wikipedia page on pip states:
One major advantage of pip is the ease of its command-line interface, which makes installing Python software packages as easy as issuing one command
So pip needs to be run from the command line.
So how do you use pip?
Since you are on Windows 7 the sure-fire way to run it is to open the start menu, type cmd, and click the first result. Then you will be running command prompt, or CMD for short. I suggest that you run pip -h to display the help for more on how to use pip.
If you have
'pip' is not recognized as an internal or external command,
operable program or batch file.
You need to add the path to your scripts folder (the solution is this SO question).
To take an excerpt, you need to execute
setx PATH "%PATH%;C:\Python34\Scripts".
Note that you need to close and re-open CMD for the change to take effect.
Good luck!
EDIT:
For future reference, if you want to set the environment variable, and Setx isn't working, you should search for Edit the system environment variables. Then go to Environment Variables->(in the second list) Path. Then double click that, and append C:\Python34\Scripts;.

Related

Not recognized as an internal or external command, operable program or batch file

Our professor has given us the assignment of downloading and setting up...
https://github.com/spyoungtech/hikvision-recover
...for a cyber security class
As stated I used pip to install from the command line. I then test to see if it was successful with
pip show hikvision-recover and it is successful.
Yet, when I try to run the command on a windows shell I get a "Not recognized as an internal or external command." I'm assuming this has to do with the command not being found? But I'm not really sure where to start.
According to documentation I should just be able to
hikvision-recover <serial number> <Date information>
and it will return the recovery password.
Update: When I try python -m I get
The executable, if it was created, is not in your path. You can try:
python -m hikvision-recover <serial number> <Date information>
It looks like the pip you used to install hikvision-recover is not the same version of python you are using. When installing a module, it is always a good practice to do the following on your command prompt:
where python
It will show you which python executable the prompt will use where invoke python.
Double check pip is the same version as python:
where pip
If the version are not the same, you need to modify your environment variable. Go Window menu - Edit the system environment variable - Environment variables - Path (User variable) and modify the order should you have more than one python version on the list.

Python console commands ignored

My computer seems to be completely ignoring everything I do with python. Every time I try to open a .py file, the console shows up for a split second, then closes immediately. This happens regardless of the content of the file. For example, it happens when I try to open this file, which is supposed to install PIP.
Additionally, whenever I open the command prompt and type any command which starts with "python", for example
python -m pip install --upgrade pip
The console completely ignores this command and produces no output.
I have tried going into my environment variables and adding the path "C:\Users\cp253\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.8".
This is what is in that folder. Could it be possible that I used the wrong path and there are more python files somewhere on my computer?
uninstall current python
install it again and add python to the path, python installer will ask you to ' add to the path' check that box and install it.
run the particular command from any other directory.

Python's uninstllation caused pip to stop working

I have uninstsalled python 3.6, and just installed 3.7. I have tried using pip on cmd, but when doing so I get this message:
Fatal error in launcher: Unable to create process using '"c:\program files\python36\python.exe" "C:\Program Files\Python36\Scripts\pip.exe" '
It seems that pip is still referencing the old python version. I know I can use py -m pip instead, but I really want to use only pip. Any solutions?
OK, the first problem is that the first pip on your PATH is one that got left behind by Python 3.6.
You can find it with where pip, and it will show you… something named pip.exe, in some standard location (like your Windows system directory?) that comes before any of your Python 3.7 directories on the your PATH.
So, find that pip.exe and delete it.
Also, make sure you no longer have the Python 3.6 directories on your PATH. (If you change this in the control panel, you will have to open a new Command Prompt window to see the effects.)
Now, either pip will just work (with 3.7), or it will tell you 'pip' is not recognized as an internal or external command, instead of trying to work with the missing 3.6 and failing.
If you get the "not recognized" error:
Python installers no longer add everything to your PATH by default. Handling Scripts directories from multiple Python installations is a nightmare, especially for novices, and it's easier to recommend everyone use py -m pip and py -m otherscript.
If you don't like that recommendation, and you're experienced enough to either avoid, or properly deal with, multiple Python installations, you can manually manage your PATH to get the old behavior.
The way to do that is pretty simple: just look inside your Python 3.7 directory, see where pip is, and add that location to your PATH.

"python" and "pip" command not found in Command Line [duplicate]

This question already has answers here:
How to add to the PYTHONPATH in Windows, so it finds my modules/packages?
(23 answers)
Closed 5 years ago.
I recently installed Python 3.6 for my Windows 10 (64bit) and I want to use pip, but before to install that, I need to execute the following command using the downloaded get-pip.py program:
python get-pip.py
Somehow this doesn't work and I get the following message from Command Line:
'python' is not recognized as an internal or external command,
operable program or batch file.
(I get the same message when I want to execute some pip commands)
I tried a lot of "solutions" for installing pip, like downloading files from https://bitbucket.org/pygame/pygame/downloads/ but nothing happened, I got the messages...
Could you explain to me why the Command Line doesn't know these commands and how can I install them?
No need for admin access:
The reason the error is arising is because python is not in your PATH (meaning it can be called from any directory in the prompt). You can check that its not in the PATH by typing the following:
echo %path%
which will return lost of different directory paths, but not the one to where you have python installed.
To add python to this (and get rid of your error), follow these steps:
Open up control panel.
Go to System. (skip to this step with: Win+Break )
Go to the Advanced tab at the top.
Click on Environment Variables at the bottom.
In the section User variables for ___, add a new one with New.
In this pop-up add the name : path and value : C:\Python34 (or wherever it is installed).
Hope this helps as this is what I did to get python to work from any directory in the command prompt!
Open your CMD as administrator and type PATH (prints the output of your system PATH Variable). There have to be a PATH directing to your Python Installation directory. Only with that system Path your cmd knows where python.exe is and search there for python.
Normally the Python Installation Setup asks if you want to set a Python Environment PATH Variable. Maybe run the setup again and watch out for that option. And I think there was a checkbox to automatic install pip for python.
If you want to set the Path Environment Variable use this:
https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10
If you want to manually install pip with GET-PIP you have to download get-pip.py first and then run it with python.
Download get-pip from here.
https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
Could you explain to me why the Command Line doesn't know these
commands and how can I install them?
This happens when Python executables are not added to PATH.
#xyres provided a nice link on how to do this.
I want to use pip, but before to install that, I need to execute the following command
using the downloaded get-pip.py program:
pip should be bundled with the official Python installer, so there should be no need to get it from other sources

pip command does nothing

I just installed Python 2.7.10 on windows 10.
I have added my python and pip directory to my PATH like so:
My Scripts folder looks like this:
My problem is, when I type in "pip" in command prompt and press enter absolutely nothing happens, even if I wait several minutes. If I remove the Scripts directory from the PATH variable I just get the error message like "pip not recognized as internal or external command". Python works fine. I have also tried to reinstall both pip and Python but the same problem occurs.
So, does anyone have any idea about why pip does not do anything?
**Edit: ** when I say it does not do anything, I mean the cmd "hangs", like if it is waiting for something to happen. The cursor just keeps on blinking.
One command that is bound to work is writing:
python -m pip install requests
This works because you hand off the script invocation to python, which you know works, instead of relying on the PATH environment variable of windows, which can be dodgy.
Packages like numpy that require c-extensions to be built, will not work with pip unless you have a C Compiler installed on your system. More information can be found in this question.
If you are, as you're saying, unfamiliar with the python environment, then let me assure you, you will have a better day by installing Anaconda.
Anaconda is a completely free Python distribution (including for
commercial use and redistribution). It includes more than 300 of the
most popular Python packages for science, math, engineering, and data
analysis.
Anaconda comes with numpy, of course.
After Python including pip at package, pip commands not work sometimes.
Then you can use pip through python like
python -m pip <pip commands that you want>
Try disabling your virus scanner. If this fixes it, exclude the C:\Python27\ folder from scanning (at your own risk).
I had this same issue: typing pip on the command line just puts the cursor on the next line, and nothing happens. I was sure my PATH system variable had C:\Python27\ and C:\Python27\Scripts\ in it, and I could verify it using echo %PATH% on the command line.
I found that I had to disable my virus scanner (Avast). I excluded the C:\Python27\ from virus scanning, and now everything works. Apparently the scanner is interfering with Python's ability to load the module.
Add the following path or you can also cd to the path and then try pip command, it will work fine.
C:\Python27\Lib\site-packages\pip
I had the same issue after uninstalling my antivirus, which was blocking the script. The issue was resolved.

Categories

Resources