2

Did any of you encountered an issue with missing tkInter when trying to compile the new Python from source on redhat 6?

"The necessary bits to build these optional modules were not found: _tkinter To find the necessary bits, look in setup.py in detect_modules() for the module's name. Failed to build these modules: binascii zlib"

It's a company interal machine. I've got an access to yum, but that's it. Yum is only finding tkInter version related to system Python which is 2.6.6.

Is there any tkInter dependency that i might be missing here? The list was longer, but installing few libraries helped. I'm still stuck with that last one and running out of ideas.

I appreciate your help.

Marcin P.
  • 21
  • 2
  • Does installing `tk-devel` help? – ChrisGPT was on strike Feb 29 '16 at 16:26
  • In general, building python on Linux requires tcl/tk installed separately and sometimes a separate python-tkinter package for tkinter/idle/turtle. Details depend on the linux distributor and maybe the version. Try looking for python-devel or *devel if Chris's answer does not work. If you do get RH 6.4 answer here, try either a RedHat list or python-list, the latter accessible via news.gmane.org. – Terry Jan Reedy Feb 29 '16 at 22:53
  • Hi guys, sorry for a late response. This is a VM so i rolled back to a snapshot and started from the beginning. The advice from Chris was good, now i'm not getting the tkInter missing exception, but something is still not right. – Marcin P. Mar 01 '16 at 09:30
  • This is how it looks now. No clear message on why it's failing (i'm just going to paste the last line before error that i got): "gcc -pthread -shared build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/_ctypes.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/callbacks.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/callproc.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/stgdict.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/cfield.o ... – Marcin P. Mar 01 '16 at 09:36
  • build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/libffi/src/prep_cif.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/libffi/src/closures.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/libffi/src/x86/ffi64.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/libffi/src/x86/unix64.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/libffi/src/x86/ffi.o build/temp.linux-x86_64-3.5/tmp/PYTHON/Python-3.5.1/Modules/_ctypes/libffi/src/x86/sysv.o -L/usr/local/lib -o ... – Marcin P. Mar 01 '16 at 09:36
  • build/lib.linux-x86_64-3.5/_ctypes.cpython-35m-x86_64-linux-gnu.so Failed to build these modules: binascii zlib" That's it. – Marcin P. Mar 01 '16 at 09:37

1 Answers1

1

On a company machine, the easiest way (if you have no permissions) is to do a custom build.

In order to build python with tkinter, you need to install tcl and tk first. I build everything with gcc and g++.

Download the tcl and tk src.tar.gz from here (make sure tcl and tk have the same version): https://www.tcl.tk/software/tcltk/download.html

# Unpack tcl
mkdir tcl_install
tar -zxvf tcl* --directory tcl_install

# configure
# say the absolute path where you want to install tcl is saved in INSTALLDIR_TCL
mkdir $INSTALLDIR_TCL # our install folder
cd tcl_install/*/unix
./configure --prefix=$INSTALLDIR_TCL CC=gcc CXX=g++ --enable-threads --enable-shared

# make install
make
make install

# cleanup
rm -rf tcl_install

And the same thing for tk, but this time specifying where you installed tcl:

# Unpack tk
mkdir tk_install
tar -zxvf tk* --directory tk_install

# configure
# say the absolute path where you want to install tcl is saved in INSTALLDIR_TK
mkdir $INSTALLDIR_TK # our install folder
cd tk_install/*/unix
./configure --prefix=$INSTALLDIR_TK --with-tcl=$INSTALLDIR_TCL/lib CC=gcc CXX=g++ --enable-threads --enable-shared

# make install
make
make install

# cleanup
rm -rf tk_install

Now we build python (download source here). We have to specify where tcl and tk are installed (edit the versions in below code). Also, before invoking make, we need to specify where the headers of tcl and tk are.

# Unpack python
mkdir python_install
tar -zxvf Python* --directory python_install

# configure
# say the absolute path where you want to install tcl is saved in INSTALLDIR_PYTHON
mkdir $INSTALLDIR_PYTHON # our install folder
cd python_install
./configure --prefix=$INSTALLDIR_PYTHON CC=gcc CXX=g++ --with-tcltk-includes="-I$INSTALLDIR_TCL/include -I$INSTLLDIR_TK/include" --with-tcltk-libs="$INSTALLDIR_TCL/lib/libtcl8.6.so $INSTALLDIR_TK/lib/libtk8.6.so"

# make install
export CPPFLAGS="-I$INSTALLDIR_TCL/include -I$INSTALLDIR_TK/include" 
make
make install

# cleanup
rm -rf python_install

Finally, copy the tcl and tk library folders to python/lib:

# copy tcl tk libs to python
cp -r tcl/lib/tcl8.6/ python/lib
cp -r tk/lib/tk8.6/ python/lib

To use the python binary with tkinter and avoid the message cannot import tkinter, you'll have to export the LD_LIBRARY_PATH before starting your app:

export LD_LIBRARY_PATH=/path_to_your_python/python/tcl/lib:/path_to_your_python/python/tk/lib:$LD_LIBRARY_PATH
/path_to_your_python/python/bin/python3.7 your_app.py # or wathever your python binary is
mfnx
  • 2,894
  • 1
  • 12
  • 28