简体   繁体   English

无法与 pip 一起安装

[英]Cannot install with pip

I've been trying to install discordpy through pip install discord.py but get a message as:我一直在尝试通过pip install discord.py 但收到如下消息:

pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ pip install discordpy
+ ~~~
    + CategoryInfo          : ObjectNotFound: (pip:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I've done this in both cmd and windows power shell and in cmd, i get the error as:我已经在 cmd 和 windows 电源 shell 和 ZDFFF0A7FA1A596C8C1A4966 中完成了此操作

'pip' is not recognized as an internal or external command, operable program or batch file. 'pip' 不是内部或外部命令、可运行程序或批处理文件。

I've tried a lot of things that I found on Stack Overflow but nothing worked.我尝试了很多在 Stack Overflow 上发现的东西,但没有任何效果。 The Python version I'm using is 3.7.我使用的 Python 版本是 3.7。

Pip is confusing when starting to use it. Pip 开始使用的时候比较混乱。 It is BOTH an command line argument AND a python method.它既是命令行参数又是 python 方法。

However, you're falling into a pitfall I did too.但是,你落入了我也犯过的陷阱。 If you want to use it as an inherent command line argument like > pip install [package] then you need to install the pip app.如果您想将其用作固有的命令行参数,例如> pip install [package] ,那么您需要安装 pip 应用程序。 Good news is that you don't NEED to do that.好消息是您不需要这样做。 Instead try running it as a python method:而是尝试将其作为 python 方法运行:

> python -m pip install [package]

Since pip is bundled with the later versions of python(>3.4), you can run pip as a method of python.由于 pip 与更高版本的python(> 3.4)捆绑在一起,因此您可以将 pip 作为 python 的方法运行。

So instead of installing using > pip install discord.py , use > python -m -3.7 pip install discord.py[voice]因此,不要安装使用> pip install discord.py ,而是使用> python -m -3.7 pip install discord.py[voice]

The -3.7 tag tells which version to install to if you have multiple versions of python.如果您有多个版本的 python, -3.7标签会告诉您要安装到哪个版本。 For example, if you are using 3.8, you would use the -3.8 tag instead例如,如果您使用的是 3.8,则应使用-3.8标记

Voice is for voice support which just adds PyNaCl to its list of dependencies and is completely optional if you are not interacting with VoiceChannels. Voice 用于语音支持,它只是将 PyNaCl 添加到其依赖项列表中,如果您不与 VoiceChannels 交互,它是完全可选的。

A common misconception is to not do pip install discord just because it says v1.0.1, but in reality, discord is just a mirror package of discord.py on PyPi because if you look deeper, discord.py is a dependency for discord . A common misconception is to not do pip install discord just because it says v1.0.1, but in reality, discord is just a mirror package of discord.py on PyPi because if you look deeper, discord.py is a dependency for discord . However, it's still recommended to install discord.py over discord但是,仍然建议在discord上安装discord.py

If you're using a VENV(Virtual ENVironment), install using the package manager or command line which comes with the IDE.如果您使用的是 VENV(虚拟环境),请使用 package 管理器或 IDE 随附的命令行进行安装。

First off, check where your python path is.首先,检查您的 python 路径在哪里。 If you already know this, that's great.如果您已经知道这一点,那就太好了。 If not, then what you should do is write in this code in如果没有,那么您应该做的是在此代码中编写

 import sys for p in sys.path: print(p)

The 4th one is your Python path.第四个是您的 Python 路径。 Open that folder, and go into the "Scripts" folder.打开该文件夹,然后 go 进入“脚本”文件夹。 Go to that path in your CMD, and use the command again. Go 到 CMD 中的该路径,然后再次使用该命令。 If you don't find a Scripts folder, go to your Python path and write in your CMD python -m pip install <module> . If you don't find a Scripts folder, go to your Python path and write in your CMD python -m pip install <module> .

Let me know if I helped you!如果我帮助了你,请告诉我!

If you get an error message saying that 'pip' or 'python' "is not recognized as an internal or external command", or something similar, you might have not adjusted your PATH system variable to include the executable paths pointing to either program.如果您收到一条错误消息,指出“pip”或“python”“不被识别为内部或外部命令”或类似内容,您可能没有调整 PATH 系统变量以包含指向任一程序的可执行路径。 Alternatively, you may need to activate your virtual environment and use python -m pip... instead.或者,您可能需要激活虚拟环境并使用python -m pip...代替。

How to adjust the PATH variable on如何调整 PATH 变量

How to activate your virtual environment:如何激活您的虚拟环境:

  1. Navigate to the directory of your venv导航到您的 venv 目录
  2. Windows: venv\Scripts\activate Unix/Mac: source venv/bin/activate (deactivate by typing deactivate) Windows: venv\Scripts\activate Unix/Mac: source venv/bin/activate(通过输入 deactivate 停用)

Note: This answer is taken from the discord.py bot, R.Danny.注意:此答案取自 discord.py 机器人 R.Danny。 You can join the official discord.py server to use the bot here: https://discord.com/invite/r3sSKJJ您可以在此处加入官方 discord.py 服务器以使用机器人: https://discord.com/invite/r3sSKJJ

Invoke command to get the response: !tag path调用命令获取响应: !tag path

You can fix it as follow:您可以按如下方式修复它:

Method 1: Reinstall Python and make sure to check ADD TO PATH while doing so.方法一:重装Python,安装时一定要勾选ADD TO PATH。

Method 2: Find the location of pip, normally it's as follow C:/Program Files/Python/scripts/pip.方法二:找到pip的位置,一般如下C:/Program Files/Python/scripts/pip。 Then open your CMD and type: setx PATH C:/Program Files/Python/scripts/pip .然后打开 CMD 并输入: setx PATH C:/Program Files/Python/scripts/pip

The reason behind your error is that PIP is installed on your computer but it's not linked with your CMD.您的错误背后的原因是 PIP 安装在您的计算机上,但它没有与您的 CMD 链接。 To link it with your CMD it has to be inside your PATH within Environment Variables.要将其与您的 CMD 链接,它必须位于环境变量中的 PATH 内。

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

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