Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore local python when building python from source

When I try to build my own version of Python using:

./configure --enable-shared --prefix=/app/vendor/python-dev && make && make install

I see some errors during installation:

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libpython2.7.a: could not read symbols: Bad value

The problem starts when the linker tries to use /usr/local/lib/libpython2.7.a and not the newly compiled library.

How can I prevent the linker (configure/make) from using the python libraries installed on the system?

like image 780
Xyand Avatar asked Jun 07 '13 14:06

Xyand


People also ask

What do I need to build Python from source?

When building python from source, you need to have already installed various libraries with your package manager. Python will compile fine without these, but your access to a lot of modules will be restricted. These are the packages I installed for my blog

How do I know if a Python build has been successful?

At the end of the build you should see a success message, possibly followed by a list of extension modules that haven’t been built because their dependencies were missing: Python build finished successfully!

Why can’t I build Python with a new version of Python?

However, this makes the Python build require an already installed Python interpreter; this can also cause version mismatches when trying to build an old (2.x) Python with a new (3.x) Python installed, or vice versa. To overcome this problem, auto-generated files are also checked into the Git repository.

Should you always develop under a pydebug build of Python?

You should always develop under a pydebug build of CPython (the only instance of when you shouldn’t is if you are taking performance measurements). Even when working only on pure Python code the pydebug build provides several useful checks that one should not skip.


1 Answers

This looks to be a misfeature of the setup.py script always including /usr/local in the search path when make builds the target sharedmods.

You'll have to manually frob the setup.py, so do the...

./configure --enable-shared --prefix=/app/vendor/python-dev

...first, then edit setup.py, find lines 442, 443, and 444 which should look like this...

if not cross_compiling:
    add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
    add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')

...and comment them out so they look like this...

# if not cross_compiling
    # add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
    # add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')

...then the make should work.

like image 148
Aya Avatar answered Nov 12 '22 06:11

Aya