-1

Getting syntax error while running the following command on terminal:

pip install gTTS File "", line 1 pip install gTTS ^

enter image description here

Steffi Keran Rani J
  • 3,667
  • 4
  • 34
  • 56
Rajat
  • 19
  • 1
  • 1
  • 6
  • 1
    the syntax error is due to running a `bash` command in the `python` interpreter. `exit()` out of python, then execute the command `pip install gTTS` from the bash command prompt `$` where you previously entered `python` – chickity china chinese chicken Jun 04 '18 at 18:40

4 Answers4

2

That's not how you run pip... You run it from the system shell like this

> pip install gTTS

or

> python -m pip install gTTS

If you want to run it from inside a script, or a python shell you do it like this

import pip

def install(package):
    pip.main(['install', package])

# Example
if __name__ == '__main__':
    install('gTTS')
sehafoc
  • 866
  • 6
  • 9
  • Thanks Sehafoc, I tried it from the shell as below and it give me another error: no module name pip so I had to install pip and it worked fine. Thanks again for your help. – Rajat Jun 04 '18 at 20:09
  • @Rajat, Sure thing buddy. – sehafoc Jun 05 '18 at 19:07
1

If you had installed Anaconda IDE, the installation gets much hassle-free as it eliminates the headaches of trying to figure out which version/release of package X is compatible with which version/release of package Y.

Just open the Conda prompt shell and type the following command and hit Enter:

pip install gTTS

Voila! The package will be successfully installed in a jiffy!

Steffi Keran Rani J
  • 3,667
  • 4
  • 34
  • 56
0

I mentioned in my reply to sehafoc I tried running the command from shell and started getting another error "no module name pip", so I installed pip by running following commands:

  1. Downloaded pip script $ curl https://bootstrap.pypa.io/get-pip.py > get-pip.py

  2. Executed the pip script by running following command $ sudo python get-pip.py

  3. Install gTTS module $ sudo pip install gTTS

Rajat
  • 19
  • 1
  • 1
  • 6
0

If you can't use your pip on your cmd. But first thing, you have to install your pip with syntax:

python -m install pip 

And don't forget to add python to your path, and then type this syntax to your cmd

python -m pip install gtts

and your gtts will dowloaded automatically

Fabian Bettag
  • 799
  • 12
  • 22