【问题标题】:pyyaml dependency error while executing with python script in PEX在 PEX 中使用 python 脚本执行时出现 pyyaml 依赖错误
【发布时间】:2021-01-11 21:07:41
【问题描述】:

我在尝试使用 PEX 打包和执行脚本时遇到以下错误。

Failed to execute PEX file. Needed macosx_10_14_x86_64-cp-38-cp38 compatible dependencies for:
 1: pyyaml
    Required by:
      app==0.0.1
    But this pex only contains:
      PyYAML-5.3.1-cp39-cp39-macosx_10_14_x86_64.whl

这是我打包文件所做的:

执行以下命令生成 zip 文件

pex requests 'XlsxWriter==1.3.7' 'urllib3==1.26.2' 'PyYAML==5.3.1' ./app -o app.pex --python-shebang '#!/usr/bin/env python3'

使用调试日志执行时,我看到以下错误

(base)$ PEX_VERBOSE=9 ./app.pex

pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Searching dependency cache: /Users[PATH]/app.pex/pex: Activating
 PEX virtual environment from ./app.pex :: Resolving pyyaml from [Requirement.parse('PyYAML==5.3.1; python_full_version != "3.0.*" and python_full_version != "3.1.*" and python_full_version pex: Failed to resolve a requirement: The 'pyyaml' distribution was not found and is required by the application                                                                                                                                                                                                            
pex: Failed to resolve a requirement: The 'PyYAML' distribution was not found and is required by app                        
pex: Activating
 PEX virtual environment from ./app.pex :: Resolving chardet from [Requirement.parse('chardet==4.0.0; python_full_version != "3.0.*" and python_full_version != "3.1.*" and python_full_versiopex: Activating
 PEX virtual environment from ./app.pex :: Resolving idna from [Requirement.parse('idna==2.10; python_full_version != "3.0.*" and python_full_version != "3.1.*" and python_full_version != "3pex: Activating
 PEX virtual environment from ./app.pex :: Resolving requests from [Requirement.parse('requests==2.25.1; python_full_version != "3.0.*" and python_full_version != "3.1.*" and python_full_verpex: Activating
 PEX virtual environment from ./app.pex :: Resolving urllib3 from [Requirement.parse('urllib3==1.26.2; python_full_version != "3.0.*" and python_full_version != "3.1.*" and python_full_versipex: Unresolved requirements:

环境:



$ python --version
Python 2.7.16


$ python3 --version
Python 3.9.1


$ python2 --version
bash: python2: command not found


$ pip --version
bash: /usr/local/bin/pip: /usr/local/opt/python@3.8/bin/python3.8: bad interpreter: No such file or directory


$ pex --version
2.1.24
$ whereis python
/usr/bin/python

【问题讨论】:

    标签: python python-3.x pyyaml pex


    【解决方案1】:

    据我看你的环境数据,你得先安装python3.8,然后再做:

    python3.8 -m pip install pyyaml
    

    你可能一开始在你的机器上安装了 python3.8,用那个 python3.8 安装了 pex,然后卸载了 python3.8。所以,现在只剩下 python3.9,但 pex 仍然配置为使用 python3.8。 pex 现在为 python3.8 查找 pyyaml,但只为 python3.9 查找 pyyaml。另一种解决方案是卸载您现在拥有的 pex,然后使用以下命令重新安装它:

    python3.9 -m pip install pex
    

    【讨论】:

    • 它已经安装好了。输出如下 - 已满足要求:/opt/anaconda3/lib/python3.8/site-packages (5.3.1) 中的 pyyaml
    • @AnmolDubey 根据您问题中的错误消息,您安装了适用于 python3.9 的 pyyaml-5.3.1,但您的 pex 应用程序需要适用于 python3.8 的 pyyaml-5.3.1。请发布python --versionpython3 --versionpython2 --versionpip --versionpex --versionwhereis python 的输出。
    • 为主要问题添加了详细信息。
    【解决方案2】:

    我通过将 env 更改为 3.9 解决了这个问题

    pex requests 'XlsxWriter==1.3.7' 'urllib3==1.26.2' 'PyYAML==5.3.1' ./app -o app.pex --python-shebang '#!/usr/bin/env python3.9'
    

    【讨论】:

    • 好的,我本可以省去我的 looooooong 编辑!不过没问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 2023-01-12
    • 1970-01-01
    相关资源
    最近更新 更多