install beautiful soup using pip


Question

I am trying to install BeautifulSoup using pip in Python 2.7. I keep getting an error message, and can't understand why.

I followed the instructions to install pip, which was installed to the following directory: c:\Python27\Scripts\pip.exe, then I tried adding it to the path, and running the pip install package command.

tried it two different ways:

import sys
sys.path.append('C:\\Python27\\Scripts\\pip.exe')
pip install beautifulsoup4

import sys
sys.path.append('C:\\Python27\\Scripts')
pip install beautifulsoup4

both give me this error message:

>>> pip install beautifulsoup4
SyntaxError: invalid syntax

the shell is highlighting the word "install" and saying that it's invalid syntax.

I have no idea what's going on, so any help would be greatly appreciated.

1
65
11/13/2013 3:07:29 PM

Accepted Answer

pip is a command line tool, not Python syntax.

In other words, run the command in your console, not in the Python interpreter:

pip install beautifulsoup4

You may have to use the full path:

C:\Python27\Scripts\pip install beautifulsoup4

or even

C:\Python27\Scripts\pip.exe install beautifulsoup4

Windows will then execute the pip program and that will use Python to install the package.

Another option is to use the Python -m command-line switch to run the pip module, which then operates exactly like the pip command:

python -m pip install beautifulsoup4

or

python.exe -m pip install beautifulsoup4
133
4/24/2018 9:22:51 PM

The easy method that will work even in corrupted setup environment is :

To download ez_setup.py and run it using command line

python ez_setup.py

output

Extracting in c:\uu\uu\appdata\local\temp\tmpjxvil3 Now working in c:\u\u\appdata\local\temp\tmpjxvil3\setuptools-5.6 Installing Setuptools

run

pip install beautifulsoup4

output

Downloading/unpacking beautifulsoup4 Running setup.py ... egg_info for package Installing collected packages: beautifulsoup4 Running setup.py install for beautifulsoup4 Successfully installed beautifulsoup4 Cleaning up...

Bam ! |DoneĀ¬


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon