2

When building python from source, you must specify a prefix which identifies the directory to install into:

./configure --prefix="/etc/py27/"
make 
sudo make altinstall 

We now have python installed in /etc/py27/

Now, ignoring environment variables, which we'll manage in a startup script, let's say we didn't want to build from source again, and wanted to relocate the Python runtime files.

I noticed that /etc/py27 path is hard coded as follows:

[/etc/py27mv]$ grep -iRI '/etc/py27' *         
bin/python2.7-config:#!/etc/py27/bin/python2.7
bin/pydoc:#!/etc/py27/bin/python2.7
bin/smtpd.py:#!/etc/py27/bin/python2.7
bin/2to3:#!/etc/py27/bin/python2.7
bin/idle:#!/etc/py27/bin/python2.7
lib/python2.7/config/Makefile:prefix=           /etc/py27
lib/python2.7/config/Makefile:CONFIG_ARGS=       '--prefix=/etc/py27/'
lib/python2.7/_sysconfigdata.py: 'BINDIR': '/etc/py27/bin',
lib/python2.7/_sysconfigdata.py: 'BINLIBDEST': '/etc/py27/lib/python2.7',
lib/python2.7/_sysconfigdata.py: 'CONFIG_ARGS': "'--prefix=/etc/py27/'",
lib/python2.7/_sysconfigdata.py: 'CONFINCLUDEDIR': '/etc/py27/include',
lib/python2.7/_sysconfigdata.py: 'CONFINCLUDEPY': '/etc/py27/include/python2.7',
lib/python2.7/_sysconfigdata.py: 'DESTDIRS': '/etc/py27 /etc/py27/lib /etc/py27/lib/python2.7 /etc/py27/lib/python2.7/lib-dynload',
lib/python2.7/_sysconfigdata.py: 'DESTLIB': '/etc/py27/lib/python2.7',
lib/python2.7/_sysconfigdata.py: 'DESTSHARED': '/etc/py27/lib/python2.7/lib-dynload',
lib/python2.7/_sysconfigdata.py: 'INCLDIRSTOMAKE': '/etc/py27/include /etc/py27/include /etc/py27/include/python2.7 /etc/py27/include/python2.7',
lib/python2.7/_sysconfigdata.py: 'INCLUDEDIR': '/etc/py27/include',
lib/python2.7/_sysconfigdata.py: 'INCLUDEPY': '/etc/py27/include/python2.7',
lib/python2.7/_sysconfigdata.py: 'LIBDEST': '/etc/py27/lib/python2.7',
lib/python2.7/_sysconfigdata.py: 'LIBDIR': '/etc/py27/lib',
lib/python2.7/_sysconfigdata.py: 'LIBP': '/etc/py27/lib/python2.7',
lib/python2.7/_sysconfigdata.py: 'LIBPC': '/etc/py27/lib/pkgconfig',
lib/python2.7/_sysconfigdata.py: 'LIBPL': '/etc/py27/lib/python2.7/config',
lib/python2.7/_sysconfigdata.py: 'MACHDESTLIB': '/etc/py27/lib/python2.7',
lib/python2.7/_sysconfigdata.py: 'MANDIR': '/etc/py27/share/man',
lib/python2.7/_sysconfigdata.py: 'SCRIPTDIR': '/etc/py27/lib',
lib/python2.7/_sysconfigdata.py: 'datarootdir': '/etc/py27/share',
lib/python2.7/_sysconfigdata.py: 'exec_prefix': '/etc/py27',
lib/python2.7/_sysconfigdata.py: 'prefix': '/etc/py27',
lib/pkgconfig/python-2.7.pc:prefix=/etc/py27

If each of these /etc/py27 references are replaced with the new location for these files, have we effectively moved the python runtime? Are there any other references, in the binaries perhaps which would necessitate building from source as the only option?

Michael Allan Jackson
  • 4,217
  • 3
  • 35
  • 45
  • What are you trying to do/achieve ? telling us *how* you're trying to achieve something is fine only after you've explained *what* are you trying to do. Maybe there's a totally different way of achieving the same thing which is much simpler (i.e. [virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/)). – Nir Alfasi Sep 06 '16 at 20:01
  • I'm creating a build that will bundle python runtime along with application files in an RPM. Docker is what we'd like to use, but it is not currently an option. We want each runtime isolated with the application files, and not shared. – Michael Allan Jackson Sep 06 '16 at 20:06
  • Then what you want is virtualenv which provides isolated environment that can be configured with a different Python version/packages per each application. Do not mess with the Python version that comes with the OS because you might end up messing the OS. – Nir Alfasi Sep 06 '16 at 20:17
  • I'm familiar with virtualenv for development, but I don't think it will work for our production environment. Executing virtualenv in the target environment won't be an option, and building in the same directory as the final install is also not an option. We just want to copy files to /etc// and call a startup script, with no prior dependencies needing to be installed. – Michael Allan Jackson Sep 06 '16 at 20:39
  • Related: http://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency – Robᵩ Sep 06 '16 at 20:52

0 Answers0