简体   繁体   English

pip install 返回无效语法

[英]pip install returning invalid syntax

I've just installed python 3.6 which comes with pip我刚刚安装了 pip 附带的 python 3.6

However, in Windows command prompt, when I do: 'pip install bs4' it returns 'SyntaxError: invalid syntax' under the install word.但是,在 Windows 命令提示符下,当我执行以下操作时: 'pip install bs4' 它在安装字下返回 'SyntaxError: invalid syntax'。

Typing 'python' returns the version, which means it is installed correctly.键入“python”返回版本,这意味着它已正确安装。 What could be the problem?可能是什么问题呢?

try this.尝试这个。

python -m  pip ...

-m module-name Searches sys.path for the named module and runs the corresponding .py file as a script. -m module-name 在 sys.path 中搜索命名模块并运行相应的 .py 文件作为脚本。

Sometimes the OS can't find pip so python or py -m may solve the problem because it is python itself searching for pip .有时操作系统找不到 pip 所以pythonpy -m可能会解决问题,因为它是 python 本身搜索pip

You need to be in the specific folder where pip.exe exists, then do the following steps:您需要在pip.exe所在的特定文件夹中,然后执行以下步骤:

  1. open cmd.exe打开cmd.exe
  2. write the following command:编写以下命令:
    cd "The 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*

尝试以管理员身份运行 cmd(在右键单击后弹出的菜单中)和/或单独输入“pip”然后

Don't enter in the python shall, Install in the command directory.不要在python中输入,安装在命令目录下。

Not inside the python pip cannot be installed inside the python.不在python里面的pip不能安装在python里面。

Even in the version 3.+ you don't have to write the python 3 instead just python.即使在版本 3.+ 中,您也不必编写 python 3,而只需编写 python。

which looks like看起来像

python -m pip install --upgrade pip

and then install others然后安装其他

python -m pip install jupyter

"D:\\Program Files\\Py\\Scripts\\pip.exe" install numpy -U "D:\\Program Files\\Py\\Scripts\\pip.exe" 安装 numpy -U

YOUR PATH to pip.exe in Python folder + install + YOUR LIB + -U在 Python 文件夹中的 pip.exe路径+安装+你的 LIB + -U

在此处输入图片说明

The OS is not recognizing 'python' command.操作系统无法识别“python”命令。 So try 'py'所以试试'py'

Use 'py -m pip'使用'py -m pip'

The problem is the OS can't find Pip.问题是操作系统找不到 Pip。 Pip helps you install packages MODIFIED SOME GREAT ANSWERS TO BE BETTER Pip 帮助您安装软件包 修改了一些更好的答案

Method 1 Go to path of python, then search for pip方法1 到python的路径,然后搜索pip

  1. open cmd.exe打开cmd.exe
  2. write the following command:编写以下命令:

Eg例如

cd C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python37-32 cd C:\\Users\\Username\\AppData\\Local\\Programs\\Python\\Python37-32

In this directory, search pip with python -m pip then install package在这个目录下,搜索PIPPython -m PIP然后安装包

Eg例如

python -m pip install ipywidgets python -m pip install ipywidgets

-m module-name Searches sys.path for the named module and runs the corresponding .py file as a script. -m module-name 在 sys.path 中搜索命名模块并运行相应的 .py 文件作为脚本。

OR或者

GO TO scripts from CMD.从 CMD 转到脚本。 This is where Pip stays :)这是皮普住的地方:)

cd C:\\Users\\User name\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts> cd C:\\Users\\用户名\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts>

Then然后

pip install anypackage pip 安装任何包

  1. First go to python directory where it was installed on your windows machine by using首先转到 python 目录,使用它安装在你的 Windows 机器上

    cmd

  2. Then go ahead as i did in the picture然后像我在图片中所做的那样继续

在此处输入图片说明

Try:尝试:

pip3 install bs4

If you have python2 installed you typically have to make sure you are using the correct version of pip.如果您安装了 python2,您通常必须确保您使用的是正确版本的 pip。

I use Enthought Canopy for my python, at first I used "pip install --upgrade pip", it showed a syntax error like yours, then I added a "!"我为我的 python 使用了 Enthought Canopy,起初我使用了“pip install --upgrade pip”,它显示了一个像你一样的语法错误,然后我添加了一个“!” in front of the pip, then it finally worked.在 pip 前面,然后它终于起作用了。

You can also go into the directory where you have your pip.exe or pip3.exe located.您也可以进入 pip.exe 或 pip3.exe 所在的目录。 For me it was on my D drive so here is what I did:对我来说,它在我的 D 驱动器上,所以这是我所做的:

D:\>cd python

D:\python>cd Scripts

D:\python\Scripts>pip3.exe install tweepy

Hope it helps希望能帮助到你

Chances are you are in the Python interpreter.您很有可能在 Python 解释器中。 Happens sometimes if you give this (Python) command in cmd.exe just to check the version of Python and you so happen to forget to come out.如果您在 cmd.exe 中提供此 (Python) 命令只是为了检查 Python 的版本,而您恰好忘记出来,有时会发生这种情况。

Try this command试试这个命令

exit()
pip install xyz

The resolution is pretty easy, altough it took me a while to figure it out.解决方法很简单,虽然我花了一段时间才弄明白。

Two ways to solve this:解决这个问题的两种方法:

1 - Short one 1 - 短的

Open your CMD and write打开你的 CMD 并写入

pip install module 
or
python -m install module

2 - Longest one 2 - 最长的

Open your CMD and check your Python version:打开您的 CMD 并检查您的 Python 版本:

python

After you confirm you are in the correct version, still in the prompt write:确认版本正确后,仍然在提示中写:

exit()

After that write:在那之后写:

pip install module 
or
python -m install module

That will do the work.这将完成工作。

I found that you can download and install pip directly by running:我发现你可以通过运行直接下载和安装pip:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then you can run然后你可以运行

python3 get-pip.py

And check the version using:并使用以下方法检查版本:

pip3 --version

I was then able to install Django然后我就可以安装 Django

pip install Django

I had this error too!我也有这个错误! I found the problem: it had error cause i opened cmd then entered python then pip!!我发现了问题:它有错误,因为我打开 cmd 然后输入 python 然后 pip ! you shouldn't enter python!你不应该输入python! just open cmd then write "pip install bs4"只需打开cmd然后写“pip install bs4”

In windows, you have to run pip install command from( python path)/ scripts path in cmd prompt在 Windows 中,您必须在 cmd 提示符下从(python 路径)/脚本路径运行 pip install 命令

C:/python27/scripts C:/python27/scripts

pip install pandas pip 安装熊猫

You need to run pip install in the command prompt, outside from a python interpreter !您需要在命令提示符下运行 pip install ,在 python 解释器之外! Try to exit python and re try :)尝试退出python并重新尝试:)

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

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