chka
chka

Reputation: 11

How to build python 3.3.2 with _bz2, _sqlite and _ssl from source

I want to build Python 3.3.2 from scratch on my SLE 11 (OpenSUSE).

During the compilation of Python I got the message that the modules _bz2, _sqlite and _ssl have not been compiled.

I looked for solutions with various search engines. It is often said that you have to install the -dev packages with your package management system, but I have no root access.

I downloaded the source packages of the missing libs, but I have no idea how to tell Python to use these libs. Can somebody help me?

Upvotes: 1

Views: 728

Answers (2)

Kevin E
Kevin E

Reputation: 3546

The short answer is you configure those packages from source and put them in somewhere inside your home directory, say, ./configure --prefix=$HOME/opt.

The path $HOME/.local might also be a good choice, since many distros seem to be including $HOME/.local/bin in the users' $PATH already (that's where pip install --user puts executables by default on Linux platforms).

Then you tell the Python build process to use the libraries in from that location by passing extra flags to the compiler and linker. I'll use the example of SQLite, for the _sqlite3 extension, because that's one I just had to do today, so I know this works:

# build and install SQLite from the autoconf version of the "amalgamated"
# source, available at https://www.sqlite.org/download.html
cd /path/to/sqlite-source
./configure --prefix=$HOME/opt
make -j8  # 8 parallel tasks
make install

# tell the C/C++ preprocessor to also look for headers in $HOME/opt/include
export CPPFLAGS="-I$HOME/opt/include"

# tell the linker to write $HOME/opt/lib into the runtime path of any binaries
# it creates; also tell it to look for extra libraries in $HOME/opt/lib
export LDFLAGS="-Wl,-rpath=$HOME/opt/lib -Wl,-rpath=$HOME/opt/lib64 \
                -L$HOME/opt/lib -L$HOME/opt/lib64"

# tell the compiler to optimize at level 3 (optional)
export CFLAGS="-O3"

# tell Python to build into your home directory; CFLAGS, CPPFLAGS, and
# LDFLAGS are automatically picked up from the environment
cd /path/to/python-source
./configure --prefix=$HOME/opt --enable-shared --enable-optimizations
make -j8 && make install

# add $HOME/opt/bin to your $PATH
cp -i ~/.bash_profile ~/.bash_profile-$(date +%Y%m%d)
echo -e '
# add homebrew software in $HOME/opt to $PATH
export PATH="$HOME/opt/bin:$PATH"' >> ~/.bash_profile

If you define them in advance, as I did above, the build-related environment variables (CFLAGS, et al.) must be exported if you expect configure to pick them up.

You will need to log out and back in in order for changes to your $PATH to take effect. You can also modify your $PATH in ~/.bashrc, but there are downsides to that. (Actually, there are downsides to both, but that's another topic.)

Some more details are available in this SO answer.

Upvotes: 1

codevinceDev
codevinceDev

Reputation: 41

I don't use that distro, but Linux Mint (it's based on Ubuntu).

In my case before the compilation of Python 3.3.2 I've installed the necessary -dev libraries: $ sudo apt-get install libssl-dev $ sudo apt-get install libbz2-dev ...

Then I've compiled and installed Python and those imports work fine.

Hope you find it useful

León

Upvotes: 0

Related Questions