Brenton Horne Brenton Horne - 3 days ago 4
Python Question

How does one get python setup.py install to use relative paths when it comes to its installed files?

I would like to use

python setup.py install
to install Spyder to
/AppDir/usr
(i.e., this is the
--prefix
that I specify to
python setup.py install
) and I would like this installation of Spyder to work even if I move the
/AppDir
directory. This presently is not the case as when I cd to the moved
/AppDir/usr/bin
(which is no longer at
/AppDir/usr/bin
but rather at
~/GitHub/mine/packaging/AppImages/recipes/spyder/AppDir/usr/bin
, as I moved it) directory and run
./spyder
from within it I get the error:

zsh: ./spyder: bad interpreter: /AppDir/usr/bin/python: no such file or directory


To make this installation of Spyder portable I believe I need the installed files of Spyder in
/AppDir/usr
to call on relative file paths instead of absolute file paths (so instead of calling on the interpreter
/AppDir/usr/bin/python
it would call on say
./python
). Is there a way to do this?

EDIT: I plan on creating an AppImage (a cross-distribution package format) from this AppDir so symbolic links will not work! As this AppImage is intended to be downloaded by others and used by others local solutions (e.g., making it run by modifying my local system like my
~/.zshrc
file) will not work!

Answer

The error you're getting results from the shebang in ./spyder. Shebangs must use absolute paths, so it cannot change automagically when you move the folder with the interpreter. In fact, the very idea behind the Filesystem Hierarchy Standard is for logical file locations to stay the same and predictable, regardless of their physical location (for Python specifically, e.g. .pyc files have absolute paths inside them so they may have to be regenerated once the installation is moved).

The simplest way out is to manually search & replace shebangs in all scripts that use that specific Python installation. See e.g. linux - How / Is it possible to install python in a portable way? - Unix & Linux Stack Exchange and Creating a Portable Python (local install) for Linux for other options.

Comments