22

I've just installed python 3.6 which comes with pip

However, in Windows command prompt, when I do: 'pip install bs4' it returns 'SyntaxError: invalid syntax' under the install word.

Typing 'python' returns the version, which means it is installed correctly. What could be the problem?

6
  • 1
    Leave the Python terminal, and use the CMD.
    – Goralight
    Dec 4, 2017 at 12:02
  • open cmd first type pip if it gives version of pip then type your command 'pip install bs4' Dec 4, 2017 at 12:03
  • 1
    Probably running PIP in python interpreter. Just open CMD and run your command Dec 4, 2017 at 12:05
  • 1
    I already said in the question that i'm using Windows command prompt (CMD)
    – zgg6a
    Dec 4, 2017 at 12:09
  • 1
    But you are inside the Python interpreter in the CMD window. You should not be. Dec 4, 2017 at 12:10

18 Answers 18

14

try this.

python -m  pip ...

-m module-name Searches sys.path for the named module and runs the corresponding .py file as a script.

Sometimes the OS can't find pip so python or py -m may solve the problem because it is python itself searching for pip.

1
  • 3
    Code-only answers are not terribly helpful. Please consider explaining what this code does, how it solves the OP's problem.
    – m00am
    Dec 4, 2017 at 12:41
11

You need to be in the specific folder where pip.exe exists, then do the following steps:

  1. open cmd.exe
  2. write the following command:
    cd "<Path to the python folder>"

or in my case, i wrote

    cd C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts
  1. then write the following command
    pip install *anypackage*
1
  • 1
    2. cd C:\Users*username*\AppData\Local\Programs\Python\Python37-32\Scripts> pip install anypackage
    – Dipak
    Apr 25, 2019 at 16:46
4

Don't enter in the python shall, Install in the command directory.

Not inside the python pip cannot be installed inside the python.

Even in the version 3.+ you don't have to write the python 3 instead just python.

which looks like

python -m pip install --upgrade pip

and then install others

python -m pip install jupyter
2

Try running cmd as administrator (in the menu that pops up after right-clicking) and/or entering "pip" alone and then

1
  • This helped me! Pip was giving 'invalid syntax' no matter what I added after 'pip'. Thanks! Dec 10, 2020 at 21:40
1

"D:\Program Files\Py\Scripts\pip.exe" install numpy -U

YOUR PATH to pip.exe in Python folder + install + YOUR LIB + -U

enter image description here

1

The OS is not recognizing 'python' command. So try 'py'

Use 'py -m pip'

1

The problem is the OS can’t find Pip. Pip helps you install packages MODIFIED SOME GREAT ANSWERS TO BE BETTER

Method 1 Go to path of python, then search for pip

  1. open cmd.exe
  2. write the following command:

E.g

cd C:\Users\Username\AppData\Local\Programs\Python\Python37-32

In this directory, search pip with python -m pip then install package

E.g

python -m pip install ipywidgets

-m module-name Searches sys.path for the named module and runs the corresponding .py file as a script.

OR

GO TO scripts from CMD. This is where Pip stays :)

cd C:\Users\User name\AppData\Local\Programs\Python\Python37-32\Scripts>

Then

pip install anypackage

1

I had this error too! I found the problem: it had error cause i opened cmd then entered python then pip!! you shouldn't enter python! just open cmd then write "pip install bs4"

0
0
  1. First go to python directory where it was installed on your windows machine by using

    cmd

  2. Then go ahead as i did in the picture

enter image description here

0

Try:

pip3 install bs4

If you have python2 installed you typically have to make sure you are using the correct version of pip.

0

I use Enthought Canopy for my python, at first I used "pip install --upgrade pip", it showed a syntax error like yours, then I added a "!" in front of the pip, then it finally worked.

0

You can also go into the directory where you have your pip.exe or pip3.exe located. For me it was on my D drive so here is what I did:

D:\>cd python

D:\python>cd Scripts

D:\python\Scripts>pip3.exe install tweepy

Hope it helps

0

Chances are you are in the Python interpreter. Happens sometimes if you give this (Python) command in cmd.exe just to check the version of Python and you so happen to forget to come out.

Try this command

exit()
pip install xyz
0

The resolution is pretty easy, altough it took me a while to figure it out.

Two ways to solve this:

1 - Short one

Open your CMD and write

pip install module 
or
python -m install module

2 - Longest one

Open your CMD and check your Python version:

python

After you confirm you are in the correct version, still in the prompt write:

exit()

After that write:

pip install module 
or
python -m install module

That will do the work.

0

I found that you can download and install pip directly by running:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then you can run

python3 get-pip.py

And check the version using:

pip3 --version

I was then able to install Django

pip install Django
0

When I use type pip install yfinance in terminal (cmd) on Mac, it shows

SyntaxError: invalid syntax pip -install yfinance File "<stdin>", line 1
    pip -install yfinance
                 ^
SyntaxError: invalid syntax

And, I finally open the Spyder, one of the development environments of python, in Anaconda Navigator.

-1

In windows, you have to run pip install command from( python path)/ scripts path in cmd prompt

C:/python27/scripts

pip install pandas

-2

You need to run pip install in the command prompt, outside from a python interpreter ! Try to exit python and re try :)

5
  • 3
    I already said in the question that i'm using Windows command prompt (CMD)
    – zgg6a
    Dec 4, 2017 at 12:09
  • Yeah but you ran python before, didn't you?
    – Elliot
    Dec 4, 2017 at 12:11
  • 1
    You should not type python before typing your pip install command, your error is typically from Python.
    – Elliot
    Dec 4, 2017 at 12:12
  • I haven't, I typed that after I got this error to make sure python was installed correctly. I've since restarted CMD
    – zgg6a
    Dec 4, 2017 at 12:13
  • is pip installed ? it should normally be with python
    – Elliot
    Dec 4, 2017 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.