0xC0000022L
0xC0000022L

Reputation: 21309

Relocatable (self-contained) Python built from source tarball inside virtualenv environment?

I have looked at the virtualenv documentation and also found this question here at StackOverflow. However, neither answer my question or I may be missing something, so I am asking.

How can I create a virtualenv environment which contains a python that doesn't depend on the (system-wide) python of the "host"? I.e. I want a fully self-contained virtualenv with its own Python 2.7 compiled from source. Another property would be important: since virtualenv isn't the same as chroot the python inside the virtualenv has to cope with different absolute paths.

I reckon the closest to what I want is a virtualenv --relocatable with its own Python installation inside.

How can I achieve that?

Rationale

I have some older Linux boxes with different versions of Python offered through the package manager. The admin won't allow me to build a more recent Python on the boxes, so I need to be able to install a Python from source into the constrained environment I have.

Properties I need:

Issues that can be ignored for the scope of this question:

Upvotes: 7

Views: 2535

Answers (2)

0xC0000022L
0xC0000022L

Reputation: 21309

Meanwhile — more than ten years later — solutions exist in the form of indygreg/python-build-standalone and astral-sh/uv which satisfy most of the needs I had back in the day.

Just leaving this here for those still in search and unhappy with the ten year old answer.

Upvotes: 0

mata
mata

Reputation: 69052

  1. get the python source
  2. ./configure --prefix=/dest
  3. make && make install

congratulations, you now have a python installation that's completely independent of the system python in /dest. Moving this directory shouldn't be a problem, if that's what you mean with 'relocatable'.

To use this installation instead of the system python, just make sure to put /dest/bin on the PATH before the standard locations.

If that's not enough for you, you can setup a virtualenv using this python installation...

Upvotes: 6

Related Questions