system packages hide appimages one
Let say that we generate a conda image with numpy packaged inside, e.g. as:
export CONDA_CHANNEL=anaconda
export CONDA_PACKAGES=numpy
./linuxdeploy-x86_64.AppImage --appdir AppDir --plugin conda -i numpy.png -d numpy.desktop --output appimage
Then if there is a system install of numpy, in /usr/local/lib/python3.7/site-packages/ it will be loaded instead of the AppImage one. You can check this by running:
sudo pip3.7 install numpy
./numpy-x86_64.AppImage -c "import numpy; print(numpy)"
sudo pip3.7 uninstall numpy
./numpy-x86_64.AppImage -c "import numpy; print(numpy)"
The reason is that at its init Python thinks it is running from a system install and as so it adds this fixed location to is search path before the AppImage site packages. You can see this by running:
./numpy-x86_64.AppImage -c "import sys; print(sys.path)"
The last item is the AppImage site packages. It is preceded by the fixed /usr/local/lib/python3.7/site-packages/ search path.
Possible solution: remove this /usr/local/lib/python3.7/site-packages/ at Python's init by adding a sitecustomize.py file to the AppImage site packages. For example as here. Note that it might happen that someone explicitly requests this location by adding it to PYTHONPATH. In this case it should not be removed from the search path.
That's quite new to me. I was pretty sure that conda stuff really is isolated.
Your solution looks somewhat elegant to me, may I just copy that (giving credit, but using this project's license)? I'm pretty confident conda supports putting your own sitecustomize.py somewhere into the prefix.
@TheAssassin : I think that it is a problem in the Python path initialisation itself. It is not meant to operate with a variable install prefix, as we have with the AppImage. Then, Python fails to properly initialise its search path for site packages, and it sets a fallback.
Please feel free to copy / adapt the sitecustomize.py file. I change the whole license to MIT to be consistent with linuxdeploy.