Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Portable Python (local install) for Linux

I'm looking to create the following:

A portable version of python that can be run on any system (with any previous version of python or no python installed) and have it pre-configured with various python packages (ie, django, lxml, pysqlite, etc)

The closest I've found to the above is virtualenv, but this only goes so far.

If I package up a nice virtualenv for python on one machine, it contains sym links to a lot of the libraries it needs. I can take those sym links and convert them to their actual files, but if I try to move this entire directory to another machine, I get seg fault after seg fault.

To launch python on a different machine, I'm using:

LD_LIBRARY_PATH=lib/ ./bin/python

and in lib/ I have all of the shared libraries I copied from the original machine. The problem here is these shared libraries might rely on other shared libraries that I'm not including, so executing this on other linux distros does not work. Probably due to it falling back on older shared libaries installed on the system that do not work with what I copied over.

Anyone have an idea on how to get this working? Is this even possible?

EDIT:

To clarify, the desired outcome is to create a tar.gz of a python binary and associated packages (django, lxml, pysqlite, etc) that can be extracted and run on any linux based system, ie (ubuntu 8.04, redhat 5, suse 11, etc), all 32bit distros, where the locally installed version of python doesn't impact what's in the tar.gz.

like image 216
Nick Avatar asked Jun 28 '12 17:06

Nick


People also ask

How do I install Python on a Linux system?

There is plenty of code out there to install virtualenv and python on just about any Linux plus OSX (probably not Windows though). Your workflow would be to install chef or Puppet (your choice), run a script to install the Python you want, then enter a virtualenv and pip install any packages you might need.

Can I use Portable Python without an installation?

You can also fork Portable Python and modify to include your application and libraries you need. It runs from any drive/network location without installation and you can pick do you want 2.x.x or 3.x.x based Python core Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.

What is portable PyPy for Linux?

Portable PyPy for Linux Portable PyPy, as the name suggests, provides portable PyPy builds for various Linux distributions. PyPy is an alternative implementation of the Python language that focuses on speed with its “Just-in-Time” compiler. In many scenarios, its performance is comparable to Java and C.

How to execute a Python file on Linux?

To execute a Python file using this version of Python, you have to run: Note that you will have to specify full path of the Python executable or use “dot slash (./)” from a terminal opened in the directory of the executable. These are the only three options available today that provides precompiled, portable binaries of Python for Linux.


2 Answers

I just tested this and it works great.

Get the copy of python you want to install and untar it and cd to the untarred folder first.

Also get a copy of setuptools and untar that.

/opt/portapy used below is of course just the name I came up with for this post, it could be any path and the full path should be tarred up and the same path should be used on any systems you put this on due to absolute path linking.

mkdir /opt/portapy
cd <python source dir>
./configure --prefix=/opt/portapy && make && make install
cd <setuptools source dir>
/opt/portapy/bin/python ./setup.py install

Make the virtual env folder inside the portapy folder.

mkdir /opt/portapy/virtenv
/opt/portapy/bin/virtualenv /opt/portapy/virtenv
cd /opt/portapy/virtenv
source bin/activate

Done. You are ready to install all of your libraries here and have the option of creating multiple virtual envs this way.

You can then tar up the whole /opt/portapy folder and transport it to any Linux system of the same arch, within reason I suspect.

I compiled 2.7.5 ond centOS 5.8 64bit and moved the folder to a Cent6.9 system and it runs perfectly.

like image 138
tahoe Avatar answered Sep 17 '22 14:09

tahoe


I faced the same problem, so I created PortableVirtualenv. Your Question is just the definition of it.

I use it as a base for commercial multiplatform app I develop. (But PortableVirtualenv is public domain - use it freely.)

If needed, you can pip-install any package and zip the whole directory to distribute also packages you need.

like image 38
MiKor Avatar answered Sep 19 '22 14:09

MiKor