3

I want to distribute my Python application to co-workers for them to use. The application will on be run on Linux systems, but the users do not have admin privileges so cannot install my application's module dependencies. I would the users to be able to untar my application and then run my main.py script. Running another one-time 'install'-type script is okay, but not much else.

PyInstaller is close to what I want. Except I would like to distribute the source code of my application as well. So the application should be stand-alone and self-contained (with or without the python interpreter is fine, preferably with), but users should be able to make small changes to the code and rerun the application. My ideal solution is to create some sort of compressed/compiled archive of all my applications module dependencies and distribute that with my application. It doesn't have to be all dependencies, but at least the non-standard packages. The application will then import modules from this archive instead of the user's PYTHONPATH.

I tried virtualenv, but having the users source the activate script was a little too much. I've been looking into numerous other solutions, but I can't find one that works for me.

BdON003
  • 131
  • 1
  • 4
  • Do you have binary dependencies? – nneonneo Sep 07 '13 at 15:58
  • By stand-alone, do you also mean self contained? I.e should your co-workers need to have Python installed to run your program? – SevenBits Sep 07 '13 at 16:00
  • 2
    Also, users can install dependencies with `pip install --user`, which does not require admin privileges. – nneonneo Sep 07 '13 at 16:00
  • No binary dependencies. Ideally I would like to package Python with my application because I know some users have different versions of Python installed. If this isn't possible then they can all get the same version installed. – BdON003 Sep 07 '13 at 16:35
  • I didn't think about `pip install --user`. Then all the user would need to do is to set their PYHTONPATH variable to include where pip installed the packages? Can I distribute a directory with all of the packages and then set the user's PYTHONPATH from within my application? – BdON003 Sep 07 '13 at 16:37
  • possible duplicate of [Creating a Portable Python (local install) for Linux](http://stackoverflow.com/questions/11249901/creating-a-portable-python-local-install-for-linux) – Burhan Khalid Sep 08 '13 at 04:59
  • See [python packaging overview](https://packaging.python.org/en/latest/overview/) and https://stackoverflow.com/q/1558385 – djvg Apr 15 '22 at 09:11

2 Answers2

1

Why don't you create a directory with the interpreter you want to use, add in any modules etc. Then drop in a bash script, say run.sh which calls the program. It can launch your chosen interpretter with your python files, arguments etc.

Any source files can remain this way and be edited in place. You could tar and distribute the whole directory, or put in something like git.

joeButler
  • 1,553
  • 1
  • 19
  • 37
  • When I copy the interpreter to another machine and execute the interpreter I get warnings about platform-independent and platform-dependent libraries not being found. I get how to copy modules from site-packages and set sys.path. Do I do something similar with the platform-dependent libraries? – BdON003 Sep 07 '13 at 18:55
0

One approach is to use virtualenv. It is designed to create isolated python environment and does a good job at it. It should be possible (link to package the virtualenv with your app with some effort. However virtualenv is not designed for that so it's not as easy as it could be.

package-virtualenv GitHub project might also help.

Lycha
  • 9,524
  • 1
  • 34
  • 43