尝试让 Python、Pip 和 Requests 全部启动并运行,但失败了

j.t*_*wis 4 python linux pip python-2.7 python-requests

我正在运行一个 Linux 服务器(Linux 4.1.12-124.19.1.el7uek.x86_64 #2 SMP Wed Sep 5 13:41:16 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux),上面有 python 2.7.5(DBA 想要它)他们的脚本为 2.7.5)并尝试让 pip 和请求运行。

我在使用 pip 时遇到问题,因为当我尝试安装 时epel-release,它会告诉我“没有名为该包的包”。所以我必须做

"yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"
Run Code Online (Sandbox Code Playgroud)

这最终让我做到了

"yum install python-pip"
Run Code Online (Sandbox Code Playgroud)

安装 pip。

然后我做了

"python -m pip install requests"
Run Code Online (Sandbox Code Playgroud)

安装请求。

它看起来不错,但是当我运行 DBA 给我检查的测试脚本时,它给了我这个。

"Traceback (most recent call last):
  File "/mnt/EBS_Cloning_Repo/clone/scripts/test.py", line 2, in <module>
    import requests
  File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 133, in <module>
    from . import utils
  File "/usr/lib/python2.7/site-packages/requests/utils.py", line 27, in <module>
    from . import certs
  File "/usr/lib/python2.7/site-packages/requests/certs.py", line 15, in <module>
    from certifi import where
  File "/usr/lib/python2.7/site-packages/certifi/__init__.py", line 1, in <module>
    from .core import contents, where
  File "/usr/lib/python2.7/site-packages/certifi/core.py", line 17
    def where() -> str:
                ^
SyntaxError: invalid syntax"
Run Code Online (Sandbox Code Playgroud)

我确实发现这可能是由于仅运行 python 命令而不是像 python2 这样的命令引起的,因此我尝试使用 python2 命令重做一些命令,得到相同的结果。

我确实有另一台服务器,它应该与此一起运行,并且我比较了它指向的文件,并看到其中缺少一些信息(差异输出一个请求),但我不确定我可以用这些信息做什么。

Ton*_*ock 6

总长DR

\n
python -m pip install requests \'certifi<=2020.4.5.1\'\n
Run Code Online (Sandbox Code Playgroud)\n

分析

\n
  File "/usr/lib/python2.7/site-packages/certifi/core.py", line 17\n    def where() -> str:\n                ^\nSyntaxError: invalid syntax"\n
Run Code Online (Sandbox Code Playgroud)\n\n

例子

\n

可选沙箱:

\n
virtualenv --python python2.7 .venv\n
Run Code Online (Sandbox Code Playgroud)\n
. .venv/bin/activate\n
Run Code Online (Sandbox Code Playgroud)\n

命令:

\n
python -m pip install requests \'certifi<=2020.4.5.1\'\n
Run Code Online (Sandbox Code Playgroud)\n

输出:

\n
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.\nCollecting requests\n  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 63 kB 599 kB/s\nCollecting certifi<=2020.4.5.1\n  Downloading certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 157 kB 5.6 MB/s\nCollecting urllib3<1.27,>=1.21.1\n  Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 138 kB 20.3 MB/s\nCollecting chardet<5,>=3.0.2; python_version < "3"\n  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 178 kB 26.0 MB/s\nCollecting idna<3,>=2.5; python_version < "3"\n  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)\n     |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 58 kB 5.5 MB/s\nInstalling collected packages: certifi, urllib3, chardet, idna, requests\nSuccessfully installed certifi-2020.4.5.1 chardet-4.0.0 idna-2.10 requests-2.27.1 urllib3-1.26.9\n
Run Code Online (Sandbox Code Playgroud)\n

  • 对我来说,手动删除文件夹“/usr/lib/python2.7/site-packages/certifi”就足够了 (3认同)