简体   繁体   中英

Why am I getting an invalid syntax error?

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) 在此输入图像描述

I then tried the Python 3.4.2 terminal(shown below)

在此输入图像描述

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.....

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

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.

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.

而不是使用PATH做任何事情我建议你在python -mpip命令行上使用pip ,就像在python -mpip install somepackage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM