2

New to Python here. I am running Python 2.7.7 x86 and Windows 7. I am trying to install the requests module. I've tried:

pip install requests

in the Python shell and in the Windows command line (cmd) (I saw this question, which suggested using cmd), and I keep getting the same error:

SyntaxError: invalid syntax

I tried to check if pip even installed correctly by running:

installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version) for i in installed_packages])
print installed_packages_list

Which I got from this question. I got [] as the output. I'm interpreting this to mean that pip wasn't successfully installed. I tried reinstalling pip by running get-pip.py, and got the output:

Requirement already up-to-date: pip in c:\python27\lib\site-packages
Cleaning up...

Which I'm interpreting as Python telling me pip was installed. I'm really confused now... how do I make sure pip is correctly installed, and then install the requests module? Any help would be appreciated.

Community
  • 1
  • 1
penGuinKeeper
  • 33
  • 1
  • 1
  • 5
  • 3
    `pip` is not supposed to be run in the Python interpreter, run it in the command prompt. Also you might have to add the path to pip.exe(It's C:\Python27\Scripts\ IIRC) to your environment variables first(don't forget to restart cmd after doing this). – Ashwini Chaudhary Jun 17 '14 at 20:19
  • pip must be added to your `PATH` environment variable to be run from the command line. It's in `C:/path/to/python/scripts` – Adam Smith Jun 17 '14 at 20:20
  • I've tried running it in cmd, but I haven't added pip to the PATH variable. I'll try that. Thanks! – penGuinKeeper Jun 22 '14 at 18:18

1 Answers1

6

This is a commonly asked question, and one for which there's hardly a canonical answer that would be on-topic for SO (honestly this is more a Superuser thing, but since it's pertinent to coding -- even though it's NOT coding by any means -- it will fly here).

If you have pip (by running get-pip.py or etc) it will exist in your Python directory. If you're running Python 2.7, let's assume that that directory lives at C:\Python27\. In which case, pip exists at C:\Python27\scripts\pip.exe.

You can add that to your %PATH%, or navigate there each time you want to use pip. Whatever is most convenient. If nothing else:

COMMAND PROMPT WINDOW:
C:\users\yourname>set PATH = %PATH%;C:\python27\scripts
C:\users\yourname>pip install requests 
Adam Smith
  • 52,157
  • 12
  • 73
  • 112
  • If your question was "How to get pip", it would be a duplicate of [this](http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows) but "How to USE pip" is a little tougher to keep on-topic for SO. – Adam Smith Jun 17 '14 at 20:31
  • I'm using python3.6 and I found the folder at C:\Users\myName\AppData\Local\Programs\Python\Python36\Scripts – Sandipan Guha Oct 01 '16 at 03:05