Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to build a single python file from multiple scripts?
    text
    copied!<p>I have a simple python script, which imports various other modules I've written (and so on). Due to my environment, my PYTHONPATH is quite long. I'm also using Python 2.4.</p> <p>What I need to do is somehow package up my script and all the dependencies that aren't part of the standard python, so that I can email a single file to another system where I want to execute it. I know the target version of python is the same, but it's on linux where I'm on Windows. Otherwise I'd just use py2exe.</p> <p>Ideally I'd like to send a .py file that somehow embeds all the required modules, but I'd settle for automatically building a zip I can just unzip, with the required modules all in a single directory.</p> <p>I've had a look at various packaging solutions, but I can't seem to find a suitable way of doing this. Have I missed something?</p> <p>[edit] I appear to be quite unclear in what I'm after. I'm basically looking for something like py2exe that will produce a single file (or 2 files) from a given python script, automatically including all the imported modules.</p> <p>For example, if I have the following two files:</p> <pre><code>[\foo\module.py] def example(): print "Hello" [\bar\program.py] import module module.example() </code></pre> <p>And I run:</p> <pre><code>cd \bar set PYTHONPATH=\foo program.py </code></pre> <p>Then it will work. What I want is to be able to say:</p> <pre><code>magic program.py </code></pre> <p>and end up with a single file, or possibly a file and a zip, that I can then copy to linux and run. I don't want to be installing my modules on the target linux system.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload