简体   繁体   English

为什么我的语法错误无效?

[英]Why am I getting an invalid syntax error?

I am following a tutorial on installing the Requests library, a HTTP library for Python. 我正在学习安装Requests库的教程,这是一个Python的HTTP库。 Requests Installation Guide 请求安装指南

The tutorial says to install the Requests library, simply run this command in my terminal 教程说安装Requests库,只需在我的终端中运行此命令即可

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) 我没有在哪个终端上运行此命令,但我在下载pip之后首先尝试了Windows cmd,用于安装和管理用Python编写的软件包的软件包管理系统(如下所示) 在此输入图像描述

I then tried the Python 3.4.2 terminal(shown below) 然后我尝试了Python 3.4.2终端(如下所示)

在此输入图像描述

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..... 对我来说这很奇怪,因为Python终端能够识别pip而不是安装.....

You are running the pip install from your shell. 您正在从 shell运行pip install Exit from the shell and run it from your . 退出 shell并从你的运行它。

pip.exe will be in the C:\\Python34\\Scripts folder. pip.exe将位于C:\\Python34\\Scripts文件夹中。 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. 如果要从任何地方运行pip,可以将该文件夹添加到PATH环境变量中,或者只需将CD放入Scripts文件夹中即可运行它。

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. 看起来你正在使用Windows机器。 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. 当您想要退出env时,还有一个停用脚本。 Make sure to activate the env whenever you are trying to run the script from the command line and all should be fine. 确保在尝试从命令行运行脚本时激活env,并且一切都应该没问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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