Search code examples
python-3.xpackagepython-3.10pex

I am unable to create a pex file with a custom pacakge inside


I was following this tutorial to add my own pacakge to .pex but this tutorial is based on python2 and I try to recreate for python3.10.6 but does not works. The structure of my package is as follow hello/init.py , hello/hello.py , hello/setup.py

hello/init.py , hello/hello.py , hello/setup.py

init.py (empty)

hello.py:

    def hello(): 
       print("hello!")

setup.py:

from distutils.core import setup
setup( name='hello', version='0.0.1', py_modules=['hello'] )

But when I try to build the pex file follow error is shown: enter image description here

$ pex hello -e hello:hello -o hello.pex
pid 282 -> /home/leraes93/.pex/venvs/607954d150b1247ce7c1a15f91d4c7d23be98298/5985ed09b49a653d6596b0e14d134c5456cf1a9f/bin/python -sE /home/leraes93/.pex/venvs/607954d150b1247ce7c1a15f91d4c7d23be98298/5985ed09b49a653d6596b0e14d134c5456cf1a9f/pex --disable-pip-version-check --no-python-version-warning --exists-action a --no-input --use-deprecated legacy-resolver --isolated -q --cache-dir /home/leraes93/.pex/pip_cache download --dest /home/leraes93/.pex/downloads/resolver_download.dbt8psp4/mnt.c.Users.PC.Documents.env_medical_app.bin.python3 hello --index-url https://pypi.org/simple 
--retries 5 --timeout 15 exited with 1 and STDERR:
Re-execing from /home/leraes93/.pex/venvs/607954d150b1247ce7c1a15f91d4c7d23be98298/5985ed09b49a653d6596b0e14d134c5456cf1a9f/bin/python
ERROR: Could not find a version that satisfies the requirement hello (from versions: none)
ERROR: No matching distribution found for hello

Solution

  • -------How to run a .pex file:----------- First install follow libraries (if bdist_wheel is not able to install skip that step)

    • pip install wheel
    • pip install pex
    • pip install bdist_wheel
    • python setup.py bdist_wheel
    • export PYTHON_ENTRYPOINT=package.my_package
    • pex --disable-cache . -e ${PYTHON_ENTRYPOINT} -o app.pex (in

    For run just run follow command: './app.pex'

    Herachy of folders: setup.py ----- `import os from setuptools import setup, find_packages APP_VERSION = os.environ.get("APP_VERSION", '0.0.0') APP_NAME = os.environ.get("APP_NAME", "api-name")

    def read(fname):
        return open(os.path.join(os.path.dirname(__file__), fname)).read()
    
    setup(
        name=APP_NAME,
        version=APP_VERSION,
        packages=find_packages(),
        package_data={"": ["setup.cfg"]},
        include_package_data=True
    )`
    

    setup.cfg ----- [pycodestyle] max-line-length = 200 ignore = W605,E402,E713,E712

    --- package
        --- my_package.py
            ---def my_function():
                    print('hello')
               my_function()
        --- __init__.py
    --- setup.py
    --- setup.cfg