1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] python pex to distribute a project

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have a python project and want to distribute it as a single file. I found PEX but found it difficult to use. Initially, I thought if my project is in a folder like the following

    <folder>\
    project.py
    submodule1
    file1.py
    file2.py
    submodule2
    file3.py
    ...


    When cd into the folder and do python project.py, it run fine. I then want to put it into a single file for distribution. I found PEX and watched "WTF is PEX". I understand the theory of PEX but unable to build a single pex file so that when I execute the file, it is the same as "python project.py"

    I try

    pex -r requirement.txt -o x.pex
    pex -r requirement.txt -c whatever ...
    pex -r requirement.txt -e whatever ...


    None of the above work, because PEX will only create a virtualenv with all the required module installed, the projects sources were not packaged into the .pex file.

    In order to put my project sources into PEX, I need to package it. So I created a setup.py and try

    pex . -o x.pex

    Then no matter how I try, I still cannot run the program. I try -c and -e switch, none of them work.

    If PEX is designed to zip all the sources along with a python virtualenv (along with all the required modules), is there a simple way that

    pex -r requirement project.py -o x.pex

    which will build a pex file, package the project sources along with the virtualenv, and run as if "python project.py"? Or there is a way except I don't know how to use pex.

    Can any one help, thanks.

    Continue reading...

Compartilhe esta Página