pip安装与python3 -m pip安装 [英] pip install vs python3 -m pip install

查看:651
本文介绍了pip安装与python3 -m pip安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在conda环境中工作,试图在其中安装软件包.在我以前的计算机上,该环境中的pip install <package name>起作用.但是在这个新的Mac上,如果我这样做,然后尝试在该环境中导入该程序包,它将无法正常工作.

I am working in a conda environment, trying to install a package into it. On my previous computer, pip install <package name> within that environment worked. But on this new Mac, if I do that, and then try to import the package in that environment, it doesn't work.

此:

pip install SpeechRecognition

python3 -m pip install SpeechRecognition

后者在下面可以工作,但前者不能:

The latter works below, but the former doesn't:

>>>import speech_recognition
>>>

此外,文件似乎指向同一位置:

Also, the files appear to be pointing to the same place:

(test) ~$ which python
/anaconda3/envs/test/bin/python
(test) ~$ which python3
/anaconda3/envs/test/bin/python3
(test) ~$ which pip
/anaconda3/envs/test/bin/pip

一切都在测试环境中运行.

everything is running from the test environment.

那是怎么回事?以及如何解决?我希望能够在隔离的环境中可靠地测试软件包.

So what's going on? and how do I fix it? I want to be able to test packages in an isolated environment reliably.

更新

仅显示pip和pip3都使用3.7,而不是我的计算机上的2.7:

just to show that pip and pip3 are both using 3.7, not 2.7 on my machine:

(base) ~$ conda activate test
(test) ~$ which pip3
/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
(test) ~$ which pip
/anaconda3/envs/test/bin/pip
(test) ~$ pip --version
pip 19.1.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

或者,这是问题吗?该pip使用与测试环境不同的3.7?如果是这样,为什么?

Or, is that the issue? that pip uses a different 3.7 from the test environment? If so, why?

推荐答案

在许多系统上,pip使用Python 2解释器,而pip3使用Python 3解释器.仅安装Python 3时,pippip3相同.知道使用哪个解释器的一种方法是读取文件pip的第一行.

On many systems, pip uses the Python 2 interpreter, while pip3 uses the Python 3 interpreter. When only Python 3 is installed, pip is identical to pip3. One way to know which interpreter is used, is to read the first line of the file pip.

python3 -m pip install等效于pip3,但至少明确表明您要使用python3.

python3 -m pip install is equivalent to pip3 but at least it's explicit that you want to use python3.

在您的情况下,看来pip使用的是Python 2解释器,但带有已为Python 3安装的模块.

In your case, it looks like pip uses the Python 2 interpreter but with the module that has been installed for Python 3. That's curious.

我建议您使用python3 -m pip install而不是依赖命令pip.

I'd recommend you to use python3 -m pip install instead of relying on the command pip.

这篇关于pip安装与python3 -m pip安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆