Use a locally built Tk for Python?

  • Thread starter Mark Summerfield
  • Start date
M

Mark Summerfield

Hi,

I have multiple Pythons locally installed so that I can test against
different versions. (On a 64-bit Debian stable system.)

All of them use the system's Tcl/Tk installation. However, I want to
make some of them use a locally build Tcl/Tk that has a small
customization.

There doesn't seem to be any --with-tk or --with-tcl options for
configure that would allow me to say where my local Tcl/Tk is.

So I ran ./configure --prefix=/home/mark/opt/py32tkmod

And then I tried editing Modules/Setup: I just uncommented and edited
the _tkinter line as follows:

_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
-L/home/mark/opt/tcltk85/lib \
-I/home/mark/opt/tcltk85/include \
-I/usr/X11R6/include \
-ltk8.5 -ltcl8.5 \
-L/usr/X11R6/lib \
-lX11

But when I run ~/opt/py32tkmod/bin/python3 tkinter-test.pyw the system
tk is being used not my customized one.

Can anyone advise?

Thanks!
 
S

Steven D'Aprano

Hi,

I have multiple Pythons locally installed so that I can test against
different versions. (On a 64-bit Debian stable system.) [...]
But when I run ~/opt/py32tkmod/bin/python3 tkinter-test.pyw the system
tk is being used not my customized one.

Can anyone advise?

I'm not sure if this will help, but it may. I had a similar problem where
my Python couldn't see my installed tk/tcl 8.5 in /usr/local/lib. The
symptom I got was that "make install" was not building _tkinter and
reported this warning:

*** WARNING: renaming "_tkinter" since importing it failed:
libtk8.5.so: cannot open shared object file: No such file or directory



I fixed this by using these commands as root:


echo /usr/local/lib > /etc/ld.so.conf.d/python27.conf
ldconfig

then running "make clean", "make", "sudo make altinstall" again.

(I used altinstall instead of install so as to avoid changing the system
Python.)

This was on a 32-bit Centos system, but I expect it should work just as
well on a 64-bit Debian system.
 
D

David

Python uses the Tkinter wrapper around TCL/TK and it remains the same no matter how may versions of TCL/TK are installed. You will have to build Tkinter against whatever version you like and make sure that it gets installed in the /usr/lib64/python directory that you want.
 
M

Mark Summerfield

Thanks for your thoughtful replies.

I don't use altinstall because using --prefix is sufficient to get a
locally built Python.

Both your suggestions require root (or sudo) and changing the system
itself. Whereas I was hoping to just build a local Python and install
my own Tcl/Tk in its lib and site-packages (which I believe is what
happens on Windows?).

Anyway, maybe that isn't possible. I will try installing my patched
Tcl/Tk system wide on an old machine and if that works I'll do it to
my main machine and rebuild my Pythons to use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top