Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip install returning invalid syntax

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?

like image 779
zgg6a Avatar asked Dec 04 '17 11:12

zgg6a


People also ask

How do I fix pip invalid syntax?

If you get a "SyntaxError: invalid syntax" when trying to install a module using pip , make sure to run the command from your shell, e.g. bash or PowerShell, and not by running a Python file that contains the pip install your_module command.

How do you fix SyntaxError invalid syntax?

You can clear up this invalid syntax in Python by switching out the semicolon for a colon. Here, once again, the error message is very helpful in telling you exactly what is wrong with the line.

Why does pip install Python raise SyntaxError?

Because you are trying to execute this on python console, please execute it on “python terminal” instead. you can do it with IPython interpreter (same syntax as the question : >>> pip install selenium ). not in regular Python interpreter. but it's still better to install pip packages with the terminal.


4 Answers

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.

like image 88
Tiago_nes Avatar answered Oct 11 '22 19:10

Tiago_nes


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*
like image 40
Dipak Avatar answered Oct 11 '22 20:10

Dipak


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
like image 31
vidyasagar mulge Avatar answered Oct 11 '22 21:10

vidyasagar mulge


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

like image 23
David Ordman Avatar answered Oct 11 '22 19:10

David Ordman