试图获取Python,pip和请求全部启动和运行,但没有这样做

发布于 2025-02-01 11:28:45 字数 1533 浏览 1 评论 0 原文

我正在运行Linux服务器(Linux 4.1.12-124.19.1.el7uek.x86_64#2 SMP Wed Sep 5 sep 5 Sep 5 13:41:16 PDT 2018 x86_64 x86_64 x86_64 x864 x86_64 x86_64 gnu/linux gnu/linux)at python 2.7.5(dbas)对于他们的脚本为2.7.5),并试图使PIP和请求运行。

我遇到了一个问题,因为当我尝试安装 epel-release 时,它会告诉我“无包”。因此,我必须做

"yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"

,最终让我要做的

"yum install python-pip"

是安装PIP。

然后,我确实

"python -m pip install requests"

要安装请求。

看起来不错,但是当我运行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"

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

我确实有另一台服务器,随着它应该运行,我比较了它指向的文件,并在其中看到了一些丢失的信息(diff输出一个请求),但是我不确定我可以用这些信息做什么。

I am running a Linux server (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) with python 2.7.5 on it (DBAs want it to be 2.7.5 for their script) and trying to get pip and requests running.

I was having a problem getting pip on, because when I would try to install the epel-release, it would tell me "no package" named that. So I had to do

"yum install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm"

Which finally let me do

"yum install python-pip"

to get pip installed.

I then did

"python -m pip install requests"

to install requests.

It looked good, but when I run the test script that the DBAs gave me to check, it gives me this.

"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"

I did find that this could be caused by running just the python command, instead of one like python2, so I try redoing some of the commands with the python2 command with the same results.

I do have another server, running as it should with this, and I compared the files that it is pointing to, and seeing some missing information in them (diff output one request), but I am not sure what I can do with that information.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送舟行 2025-02-08 11:28:45

TLDR

python -m pip install requests 'certifi<=2020.4.5.1'

分析

  File "/usr/lib/python2.7/site-packages/certifi/core.py", line 17
    def where() -> str:
                ^
SyntaxError: invalid syntax"
  • 它使用Python 2.7

  • ; str in def whese() - &gt; str 是一种类型注释

    • python 3.0 引入了a 函数注释语法 in pep 3107

    • pep 484 https://docs.python.org/3/library/typing.html#module-typing“ rel =” nofollow noreferrer“> 键入 module


    • python 2.7如果找到注释,肯定会提高无效的语法

      test.py:

       类myclass(对象):
          def测试(self) - &gt;布尔:
              返回true
       

      输出:

        python ./test.py
        文件“ ./test.py”,第2行
        def测试(self) - &gt;布尔:
                       ^
        语法:无效语法
       


  • 测试
  • 认证被隐式地作为亚依赖性/子包

    • 我们可以在安装时使用PIP的解析器来固定依赖性

我们可以使用PIP的解析器在安装示例示例

virtualenv --python python2.7 .venv
. .venv/bin/activate

命令:

python -m pip install requests 'certifi<=2020.4.5.1'

输出:输出:

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.
Collecting requests
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 599 kB/s
Collecting certifi<=2020.4.5.1
  Downloading certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
     |████████████████████████████████| 157 kB 5.6 MB/s
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 20.3 MB/s
Collecting chardet<5,>=3.0.2; python_version < "3"
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     |████████████████████████████████| 178 kB 26.0 MB/s
Collecting idna<3,>=2.5; python_version < "3"
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 5.5 MB/s
Installing collected packages: certifi, urllib3, chardet, idna, requests
Successfully installed certifi-2020.4.5.1 chardet-4.0.0 idna-2.10 requests-2.27.1 urllib3-1.26.9

TLDR

python -m pip install requests 'certifi<=2020.4.5.1'

Analysis

  File "/usr/lib/python2.7/site-packages/certifi/core.py", line 17
    def where() -> str:
                ^
SyntaxError: invalid syntax"
  • It's using python 2.7

  • The -> str in def where() -> str is a type annotation

    • Python 3.0 introduced a function annotation syntax in PEP 3107

    • Python 3.5 officially adds standard definitions for them via PEP 484's typing module

    • Python 2.7 would definitely raise invalid syntax if it found an annotation

      test.py:

      class MyClass(object):
          def test(self) -> bool:
              return True
      

      Output:

      ❯ python ./test.py
        File "./test.py", line 2
        def test(self) -> bool:
                       ^
        SyntaxError: invalid syntax
      
  • certifi

    • Certifi dropped python 2.7 in 2020.04.05.2 (commit)
    • Certifi's last python 2.7 release is 2020.04.5 (github)
  • certifi is being implicitly fetched as a sub-dependency / sub-package

    • We can use pip's resolver to pin the dependency while installing

Example

Optional sandbox:

virtualenv --python python2.7 .venv
. .venv/bin/activate

Command:

python -m pip install requests 'certifi<=2020.4.5.1'

Output:

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.
Collecting requests
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 599 kB/s
Collecting certifi<=2020.4.5.1
  Downloading certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
     |████████████████████████████████| 157 kB 5.6 MB/s
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 20.3 MB/s
Collecting chardet<5,>=3.0.2; python_version < "3"
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     |████████████████████████████████| 178 kB 26.0 MB/s
Collecting idna<3,>=2.5; python_version < "3"
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 5.5 MB/s
Installing collected packages: certifi, urllib3, chardet, idna, requests
Successfully installed certifi-2020.4.5.1 chardet-4.0.0 idna-2.10 requests-2.27.1 urllib3-1.26.9
像极了他 2025-02-08 11:28:45

我认为这是一个兼容性错误。 PIP损坏,我尝试了 YUM删除Python2-PIP 并重新安装它。我认为经过错误认证的依赖性使它不利。因此,您可以复制将良好的认证依赖性文件与已发行的PC复制。位置为/usr/lib/python2.7/site-packages/

I think this is a compatibility bug. The pip is broken, I tried yum remove python2-pip and reinstalling it. I think the error-certified dependency makes it bad. So you can COPY the good certified dependency files to the destinated PC. The location is /usr/lib/python2.7/site-packages/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文