【问题标题】:I am unable to create a pex file with a custom pacakge inside我无法创建内部包含自定义包的 pex 文件
【发布时间】:2023-01-30 23:26:56
【问题描述】:

我正在按照 this 教程将我自己的 pacakge 添加到 .pex,但本教程基于 python2,我尝试为 python3.10.6 重新创建但不起作用。 我的包的结构如下你好/在里面.py , 你好/你好.py , 你好/setup.py

在里面.py(空)

你好.py:

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

安装程序.py:

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

但是当我尝试构建 pex 文件时,会显示以下错误:

$ 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

【问题讨论】:

    标签: python-3.x package python-3.10 pex


    【解决方案1】:

    --------如何运行.pex文件:------------ 首先安装跟随库(如果 bdist_wheel 无法安装跳过该步骤)

    • pip 安装轮
    • pip 安装 pex
    • pip 安装 bdist_wheel
    • python setup.py bdist_wheel
    • 导出 PYTHON_ENTRYPOINT=package.my_package
    • pex --禁用缓存。 -in ${PYTHON ENTRYPOINT} -o app.pex(在

    对于运行,只需运行以下命令:'./app.pex'

    文件夹层次结构: 安装程序.py ------ `导入操作系统 从 setuptools 导入设置,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
    )`
    

    安装程序配置文件 ------ [pycodestyle] 最大行长 = 200 忽略 = W605,E402,E713,E712

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      相关资源
      最近更新 更多