36

I downloaded and installed Python 3.5 from https://www.python.org/downloads/ on my Windows 10 machine with IDLE

I want to install other packages using pip using the following and various other options in the IDLE commandline editor.

>> pip install    packagename
>> pip --install  packagename
>> pip --upgrade  packagename
>> pip upgrade    packagename

Where packagename I have tried various packages available from my installed Python modules Tried all the above options without any packagename a well. In short, pip doesn't work and I am stuck.

I get Syntaxerror: invalid syntax

pip is preinstalled in my Python. confirmed this with the command "import pip" and from help('modules').

Need help on how to proceed.

System specs: Windows 10, with login as User (Local Admin privileges). this is the only User on my computer.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335

10 Answers10

58

instead of typing in "python". try using "py". for ex:

py -m pip install    packagename
py -m pip --install  packagename
py -m pip --upgrade  packagename
py -m pip upgrade    packagename

note: this should be done in the command prompt "cmd" and not in python idle. also FYI pip is installed with python 3.6 automatically.

Dmitry
  • 6,716
  • 14
  • 37
  • 39
BJJ Vegan
  • 581
  • 4
  • 3
  • 1
    I use pwsh 7 as admin and get: `py: The term 'py' is not recognized as a name of a cmdlet, function, script file, or executable program.`. What is `py`? – Timo Apr 24 '21 at 10:50
14

Make sure the path to scripts folder for the python version is added to the path environment/system variable in order to use pip command directly without the whole path to pip.exe which is inside the scripts folder.

The scripts folder would be inside the python folder for the version that you are using, which by default would be inside c drive or in c:/program files or c:/program files (x86).

Then use commands as mentioned below. You may have to run cmd as administrator to perform these tasks. You can do it by right clicking on cmd icon and selecting run as administrator.

python -m pip install packagename
python -m pip uninstall packagename
python -m pip install --upgrade packagename

In case you have more than one version of python. You may replace python with py -versionnumber for example py -2 for python 2 or you may replace it with the path to the corresponding python.exe file. For example "c:\python27\python".

Nikita Sharma
  • 149
  • 1
  • 8
7

It's a really weird issue and I am posting this after wasting my 2 hours.

You installed Python and added it to PATH. You've checked it too(like 64-bit etc). Everything should work but it is not.

what you didn't do is a terminal/cmd restart

restart your terminal and everything would work like a charm.

I Hope, it helped/might help others.

Mujeeb Ishaque
  • 2,259
  • 24
  • 16
3

I faced a problem upgrading pip from version 9.0.1 to 9.0.3 The upgrade failed middle way(after uninstalling version 9.0.1 and without installing version 9.0.3). This usually creates a broken pip file. Broken pip can be solved by the command-->

easy_install pip

Which usually installs the latest version of pip, and solves the issue. In order to confirm, type

pip --version

Hope this was helpfull...

J11
  • 455
  • 4
  • 8
3

According to pip documentation

pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4 downloaded from python.org

But I was surprised when I typed pip --version in the Python Launcher and it gave me an error saying that 'pip' is not recognized. Then I tried the same in Python IDLE which gave the same error. Then I opened a cmd and typed python pip --version and it said something like "can't open file".

Solution:

I finally realized that pip commands are properly recognized outside of the python.exe, because pip is a separate executable. So, just open a cmd and type pip --version and it should work as expected. If you call pip inside a Python executable (such as the Launcher, IDLE, or calling python pip), it assumes pip is just a variable and complains that it is not defined.

Note: I made sure that C:\Users\<username>\AppData\Local\Programs\Python\<Python version>\ and C:\Users\<username>\AppData\Local\Programs\Python\<Python version>\Scripts\ are included in the PATH variable.

dee
  • 119
  • 1
  • 3
  • 2
    Says `'pip' is not recognized as an internal or external command, operable program or batch file.` – Jake Sep 02 '21 at 12:07
2

You should use python and pip in terminal or powershell terminal not in IDLE.

Examples:

pip install psycopg2

or

python -m pip install psycop2

Remember about add python to Windows PATH. I paste examples for Win7. I believe in Win10 this is similar.

Adding Python Path on Windows 7

python 2.7: cannot pip on windows "bash: pip: command not found"

Good luck:)

Community
  • 1
  • 1
MartinP
  • 527
  • 5
  • 17
  • Doesn't work from Windows command line. Adding the path in Windows 10, seems Windows 10 doesn't allow. –  Oct 04 '16 at 15:14
  • Seems windows PATH not contain python. You can try run python from python directory - cd C:\python\directory and run python.exe. If python run You can try above system commnands from this directory. If works I am confident You should add python to windows PATH if You want run python from other directories. – MartinP Oct 05 '16 at 12:56
0

open command prompt

python pip install <package-name> 

This should complete the process

Pavan Nath
  • 1,494
  • 1
  • 14
  • 23
0

You may have to run cmd as administrator to perform these tasks. You can do it by right clicking on cmd icon and selecting run as administrator. It's worked for me.

Igor Osipov
  • 157
  • 1
  • 12
0

I had the same problem on Visual Studio Code. For various reasons several python versions are installed on my computer. I was thus able to easily solve the problem by switching python interpreter.

If like me you have several versions of python on you machine, in Visual Studio Code, you can easily change the interpreter by clicking on the bottom left corner where it says Python...

enter image description here

0

This command fixed my problem:

pip install --user mpr

Tohid Makari
  • 1,700
  • 3
  • 15
  • 29