Why am I getting an invalid syntax error?

30,667

Solution 1

You can also create a virtual environment for your project and install all the modules you would like to use. It looks like you are using a windows machine. The commands would be as follows

C:dirrectory_for_your_project>c:\Python34\python.exe c:\Python34\Tools\Scripts\pyvenv.py env  #create your environment
C:dirrectory_for_your_project>env\Scripts\activate.bat   #activate your enviornment
(env) C:dirrectory_for_your_project>pip install requests #pip modules you would like to include in your project
(env) C:dirrectory_for_your_project>python script.py     #run script

There is also a deactivate script for when you would like to exit the env. Make sure to activate the env whenever you are trying to run the script from the command line and all should be fine.

Note: This is just another solution to your problem and is based on personal preference. You should still add the necessary scripts to your path as this might come in handy in the future.

Solution 2

You are running the pip install from your shell. Exit from the shell and run it from your .

Solution 3

pip.exe will be in the C:\Python34\Scripts folder. You can add that folder to your PATH environment variable if you want to run pip from anywhere, or you can just CD into the Scripts folder from where you are and run it.

Solution 4

Instead of doing anything with PATH I suggest you use pip on command line with python -mpip, as in python -mpip install somepackage.

Share:
30,667
committedandroider
Author by

committedandroider

Updated on July 09, 2022

Comments

  • committedandroider
    committedandroider almost 2 years

    I am following a tutorial on installing the Requests library, a HTTP library for Python. Requests Installation Guide

    The tutorial says to install the Requests library, simply run this command in my terminal

    pip install requests
    

    I didn't which terminal to run this command in but I first tried Windows cmd after downloading pip, the package management system used to install and manage software packages written in Python(shown below) enter image description here

    I then tried the Python 3.4.2 terminal(shown below)

    enter image description here

    Does anyone know which terminal to run this command in and what my syntax error is for that terminal(tried both)? To me it's weird because the Python terminal was able to recognize pip but not install.....

  • committedandroider
    committedandroider about 9 years
    Thank you! I did run it from my Windows shell program - CMD. Issue was I needed to add it to my Path environmental variable. Is bash just cmd by the way?
  • committedandroider
    committedandroider about 9 years
    Where did you get c:\Python34\Tools\Scripts\pyvenv.py from? I don't have pyvenv.py(Python extension) in my Scripts directory.
  • dparadis28
    dparadis28 about 9 years
    You should see it when you look in the directory. It comes with py 3.4. Make sure you are looking in the right directory. There is a scripts folder directly in python34 with scripts such as easy_install.py and pip.py. That is not the directory you should be in. You need to look in tools then scripts. If you still don't see it, just upgrade your python version to the latest python 3.4.3 (as it may have been a recent add that did not exist in the version of python you are using). Oh and something else I forgot to mention. You can run win_add2path.py to configure python in your path variables
  • committedandroider
    committedandroider about 9 years
    When you write out the command, do you actually put the env in parenthesis?
  • A.J. Uppal
    A.J. Uppal about 9 years
    @committedandroider yep :)