Search code examples
pythonpython-3.xpyyamlpex

pyyaml dependency error while executing with python script in PEX


I am getting the following error while trying to package and execute a script with 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

Here is what i did to package the file :

Executed following command to generate zip file

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

when executing with debug logs, i see following errors

(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:

Environment :



$ 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/[email protected]/bin/python3.8: bad interpreter: No such file or directory


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

Solution

  • As far as i can see from your environment data, you have to install python3.8, and then do:

    python3.8 -m pip install pyyaml
    

    You probably had python3.8 installed on your machine at first, installed pex with that python3.8, and then uninstalled python3.8. So, now there is only python3.9 left, but pex is still configured for using python3.8. And pex now looks for pyyaml for python3.8, but only finds pyyaml for python3.9. Another solution would be to uninstall the pex you have right now, and then reinstall it with following command:

    python3.9 -m pip install pex