4

I try to run some Python programs in chroot and I get the following error

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback

I used ldd to find the libraries on which the python runtime depends and copied the inside the jail. Could you please help me with that?

Thank you

Paris
  • 6,323
  • 7
  • 31
  • 49

2 Answers2

4

You'll want to grab files from /usr/lib/pyshared and /usr/lib/python{$version} and copy them into your chroot.

Paths may be slightly different, you can try an strace python to see what its trying to load up.

Null
  • 41
  • 2
  • 3
    worked for me I copied: `/usr/lib/py* /usr/share/py*` and after that I copied the libraries I from `find /usr/lib/python{$version}/ -name '*.so' -exec ldd {} \; ` – Michal Stawski Feb 26 '15 at 04:59
2

That is because some libraries are not visible from the chroot environment.

Copy them or mount them using mount --bind.

Just to illustrate what I mean (of course you need not to copy all the libraries):

# cp -R /usr/lib /home/user/chroot/usr/lib

Or, using mount bind:

# mount --bind /usr/lib /home/user/chroot/usr/lib
Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
  • Is there any way to know which of these libraries are used by Python? So as not to copy useless files – Paris Aug 01 '12 at 11:31
  • You can try to start with `ldd /usr/bin/python`. But there can be other libraries also. Try to check with `mount --bind` if it helps. `mount` doesn't copy files, only makes special mapping. – Igor Chubin Aug 01 '12 at 11:42