尝试安装模块时出现Python`no module pip .__ main __;`错误 [英] Python `no module pip.__main__;` error when trying to install a module

查看:165
本文介绍了尝试安装模块时出现Python`no module pip .__ main __;`错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Raspberry Pi上遇到以下错误:No module named pip__main__; 'pip' is a package and cannot be directly executed

I am getting the following error on my Raspberry Pi: No module named pip__main__; 'pip' is a package and cannot be directly executed

当我输入终端时:sudo python3 -m pip install mp3play

是什么原因引起的,如何解决它,以便可以安装模块mp3play?

What is causing this and how can I fix it so that I can install the module mp3play?

推荐答案

Pip不仅是独立的可执行文件,还是python模块.

Pip is not only a standalone executable, it is also a python module.

实际上,在python文档中,它直接建议使用-m语法来使用pip安装软件包.

In fact in the python docs it directly recommends using the -m syntax for installing a package using pip.

请参见 https://docs.python.org/3.5/installing /index.html#basic-usage :

所有标准包装工具都旨在从命令行使用.

The standard packaging tools are all designed to be used from the command line.

以下命令将从Python Packaging Index中安装模块的最新版本及其依赖项:

The following command will install the latest version of a module and its dependencies from the Python Packaging Index:

python -m pip install SomePackage

我的猜测是系统的pip(可执行文件)被pip可执行文件的python2版本所遮盖.但是听起来您没有安装pip(模块),以便您的python3可执行文件可以找到它,因此您可能需要专门重新安装pip(模块).

My guess would have been that your system's pip (the executable) was being shadowed by the python2 version of the pip executable. But it sounds like you don't have pip (the module) installed such that your python3 executable can find it, so you may need to reinstall pip (the module) specifically.

为此,请使用python3 -m ensurepip(用于确保信息的文档)如果您的python3解释器的视角中不存在pip,则会安装pip.

For that use python3 -m ensurepip (docs for ensurepip) which will install pip if it is not present from the persepctive of your python3 interpreter.

另一个问题可能是它在当前目录中找到名为pip的文件,可执行文件或目录,并且试图将pip视为模块,而实际上不是模块.

The other issue could be that it's finding a file, executable or directory called pip in your current directory, and it is trying to treat that pip as a module, and it is not in fact a module.

如果不是这样,我不确定.但这绝对不是因为pip不是模块.

If it's not that I'm not sure. But it is definitely not because pip is not a module.

这篇关于尝试安装模块时出现Python`no module pip .__ main __;`错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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