9

I am using Python 2.7.9 on a Windows 8 computer.

I tried to install lxml by typing pip install lxmlin Windows PowerShell after typing python, but I get the following error: SyntaxError: invalid syntax

I tried installing pip by using the following tutorial http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/ only to later realize that I already had pip.exe, pip2.7.exe and pip2.exe installed when I first installed Python. They are located in the C:\Python27\Scripts directory.

Yet, if I try something like pip help I will get an invalid syntax error.

Do I have to reinstall pip or how do I get it to work in order to install the lxml library.

Thank you for any help you can provide.

David
  • 431
  • 2
  • 7
  • 18

2 Answers2

15

I had the same problem. You need to set the PATH environment variable, so that the system recognizes the command "pip".

If typing easy_install or pip [in PowerShell] doesn’t work, it means the Scripts folder is not in your path. Run the next command in that case (Note that this command must be run only once or your PATH will get longer and longer). Make sure to replace c:\Python33\Scripts with the correct location of your Python installation:

setx PATH "%PATH%;C:\Python33\Scripts"

Close and reopen PowerShell after running this command.

Source: http://arunrocks.com/guide-to-install-python-or-pip-on-windows/

Jeremy Thompson
  • 52,213
  • 20
  • 153
  • 256
Christopher
  • 166
  • 1
  • 2
2

Starting from Python versions 2.7.9 and 3.4.0, 'pip' is already included in the regular install. Check if the path to the 'Scripts' directory inside your Python installation directory is contained in your system's 'PATH' environment variable, so 'pip' can be found.

Look here for more information:

How do I install pip on Windows?

Edit: Sounds like you are trying to run pip inside python, You shouldn't get an 'invalid syntax' error through the command prompt. More like "'pip' is not recognized". Try simply just opening command prompt and typing 'pip help'

Community
  • 1
  • 1
user3636636
  • 2,021
  • 13
  • 26
  • Hi, thank you. I just tried your solution but I keep getting the invalid syntax error. I edited the system's PATH and added the C:\Python27\Scripts directory to it and started Windows PowerShell again, but it didn't seem to work – David Jun 21 '15 at 10:37
  • Did you try the second step in the link? running - C:\PythonXX\Tools\Scripts\win_add2path.py – user3636636 Jun 21 '15 at 10:57
  • I just did it without starting Python, by just entering the Powershell and typing: `pip install lxml` and it worked. To be honest I am not sure what was the solution but thank you very much. It really helped me to understand some concepts involved in this problem – David Jun 21 '15 at 11:16
  • 2
    Sounds like you are trying to run pip inside python, is that the case? You shouldn't get an 'invalid syntax' error through the command prompt. More like "'pip' is not recognized" Try simply just opening command prompt and typing 'pip help' – user3636636 Jun 21 '15 at 11:16
  • Yes, exactly that. Thank you very much. :) – David Jun 21 '15 at 11:17