【问题标题】:python: can't open file 'help': [Errno 2] No such file or directorypython:无法打开文件'帮助':[Errno 2]没有这样的文件或目录
【发布时间】:2023-06-10 22:59:01
【问题描述】:

我正在尝试在我的 cpanel 项目上安装 python 包。但面临奇怪的问题。以下是各种命令的 cpanel 输出:

[root@host myproject]# python
Python 2.7.5 (default, Apr 11 2018, 07:36:10)[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2Type "help", "copyright", "credits" or "license" for more information.

当我尝试命令帮助时,得到以下响应:

[root@host myproject]# python help
python: can't open file 'help': [Errno 2] No such file or directory

我正在尝试从名为“myproject”的项目目录安装软件包。在安装软件包时,我得到了相同的响应:

[root@host myproject]# python install requests
python: can't open file 'install': [Errno 2] No such file or directory[root@host myproject]#

我从错误日志中了解到,python 命令无法正常工作/无法识别。我已经搜索了各种解决方案,但找不到有关此问题的任何解决方案。这里的任何人都可以帮我强调我可能犯的错误吗?以及如何解决?

【问题讨论】:

  • 你能用pip install requests代替python命令吗?
  • 首先,请上一门python课程,知道自己在做什么。其次,所有这些命令都是错误的,求助输入python --help,安装模块输入pip install package
  • 1. python --help 2. pip 安装请求

标签: python python-2.7 python-requests


【解决方案1】:

简而言之:

要显示命令帮助,您需要运行

python --help

(不是python help,它指示python运行一个名为help的文件)

要安装一个包,你需要运行pip(python包管理器):

pip install your-package-name

【讨论】:

  • python 2.7版本如何安装pip?
  • @SairaNawaz 这取决于您的操作系统,在 Windows 上,Python 发行版必须已经包含 pip,在许多 Linux 发行版上它也应该可以工作。否则,请使用操作系统的包管理器安装 pip(或可能的其他名称,例如 python2-pip)包。
【解决方案2】:

当您调用python help 时,您正在尝试打开文件help。你想要的是打电话给python --help。如果你想安装请求,你可以做pip install requests

【讨论】:

  • 好的,让我检查一下,因为 python 2.7 pip 默认情况下无法安装,所以我尝试了该命令