Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiled Python binary reports wrong version

I tried to compile Python 2.7 from source.
Here are my commands:

./configure --prefix=/my/local/dir --exec-prefix=/my/local/dir --enable-shared --with-pydebug
make
make install

And the output of which python is /my/local/dir/bin/python, which is correct.

But when I ran python --version I see Python 2.7.3 instead of Python 2.7.10.

The system version of Python is 2.7.3. Could it be the system version of Python somehow links itself against the local, compiled version? Or am I doing something wrong?

Edit:

The output of ./my/local/dir/bin/python --version is also Python 2.7.3

Edit 2:

Seems like if I get rid of the --enable-shared flag it will produce the correct version of Python, but I need that flag for my other software to work.

like image 736
mpang Avatar asked Jul 11 '15 21:07

mpang


3 Answers

So this post is able to fix my issue. To quote the source:

If you try to run a --enable-shared python executable from its build directory, you'll need to tell the dynamic loader where to find the shared library, i.e. the build directory itself. One way to do that is to use the LD_LIBRARY_PATH environment variable. Otherwise, the dynamic loader will search the standard paths, like /usr/local/lib/ and /usr/lib/ for a shared library with the proper name (like libpython2.7.so.1.0). If there is an older Python already installed with that name and if the ABI hasn't changed too much, you may be lucky and it will load and run.

like image 57
mpang Avatar answered Nov 06 '22 23:11

mpang


Remember that shells cache the location of binaries instead of looking in PATH every time.

So, if you have run python previously in the same shell, it will still use the old version.

Use hash -r to fix this without starting a new shell.

like image 2
o11c Avatar answered Nov 07 '22 00:11

o11c


It's likely you need to change the PYTHONHOMEenvironment variable so it uses the new version:

export PYTHONHOME=/my/local/dir/

https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME

*If you want to make the change permanent consider adding it to your shell profile.

like image 1
l'L'l Avatar answered Nov 06 '22 23:11

l'L'l