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.
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.
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.
It's likely you need to change the PYTHONHOME
environment 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With