9

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.

7
  • What happens if you run /my/local/dir/bin/python --version? If this case is correct, then your shell is simply caching the location of python, as o11c mentioned. Commented Jul 11, 2015 at 22:33
  • @Laogeodritt The output is still Python 2.7.3 Commented Jul 12, 2015 at 0:40
  • On some systems, which is implemented as a program instead of a shell builtin and might not tell you what the shell will really run. Best to look at whatever command tells you what the shell really thinks. For bash, that command is type. Look at help type for more. Commented Jul 12, 2015 at 0:41
  • @MikeDeSimone type python still gives the same result Commented Jul 12, 2015 at 0:47
  • It'll tell you if the path is hashed (and hash -r would clear it). You might also want to try type -a python which will list all the pythons on your path, in order. Commented Jul 12, 2015 at 3:29

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

It seems that an export LD_LIBRARY_PATH=. is required to make this work.
2

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.

1 Comment

I tried that and it didn't work. And I run ./my/local/dir/bin/python --version and it still gives Python 2.7.3
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.