configure tkinter for python3.4.2
In order to build python3.4.2 from source with the _tkinter
module you need to install the following build dependency:
sudo apt-get install tk8.6-dev
Then all you have to do is running make
again to add _tkinter
support as the setup.py
file will automatically detect the tk/tcl headers and create the module:
~/Downloads/Python-3.4.2$ make
running build
running build_ext
building '_tkinter' extension
gcc -pthread -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DWITH_APPINIT=1 -I/usr/include/tcl8.6 -I/usr/X11/include -I./Include -I. -IInclude -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/home/sylvain/Downloads/Python-3.4.2/Include -I/home/sylvain/Downloads/Python-3.4.2 -c /home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.c -o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.o
gcc -pthread -fPIC -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Werror=declaration-after-statement -DWITH_APPINIT=1 -I/usr/include/tcl8.6 -I/usr/X11/include -I./Include -I. -IInclude -I/usr/include/x86_64-linux-gnu -I/usr/local/include -I/home/sylvain/Downloads/Python-3.4.2/Include -I/home/sylvain/Downloads/Python-3.4.2 -c /home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.c -o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.o
gcc -pthread -shared build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/_tkinter.o build/temp.linux-x86_64-3.4/home/sylvain/Downloads/Python-3.4.2/Modules/tkappinit.o -L/usr/X11/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -ltk8.6 -ltcl8.6 -lX11 -o build/lib.linux-x86_64-3.4/_tkinter.cpython-34m.so
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _sqlite3
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
[...]
Now you can import tkinter in python3.4.2:
~/Downloads/Python-3.4.2$ ./python
Python 3.4.2 (default, Oct 30 2014, 11:34:17)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
Original answer:
Unless you really need python3.4.2, I would just use the default python3 version on 14.04 (3.4.0)
Then all you have to do is installaling the following packages:
sudo apt-get install python3-tk tk
And start the python interpreter this way:
/usr/bin/python3
Otherwise you'll always get the version that you installed in /usr/local
(3.4.2).
Importing tk in python3 should work now:
$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>
Related videos on Youtube
Comments
-
devGeek over 1 year
I recently met a problem while installing the newest python3.X.
Installed it using thePython-3.4.2.tar.xz
package frompython.org
After, the intallation I tried importing thetkinter
module but didn't succeed.The output of
import tkinter
was:>>> import tkinter Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/tkinter/__init__.py", line 38, in import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named '_tkinter'
I also tried following solutions:
but none of them helped.
While trying these solutions, if noticed that the error says:import _tkinter # If this fails your Python may not be configured for Tk
then i googled about it and found this.
Reading the Checking your Tkinter support section, theStep 1
failed and was stuck in this lineIf you install Tcl/Tk in the default locations, simply rerunning "make" should build the _tkinter extension.
Regarding above line, my question is:
Where to find a make file to run amake
command on ?And, how do I configure the
tkinter
so that Python3.4.2 accepts it ?
EDIT:
I forgot to mention but
import tkinter
do works for the default installation (Python-3.4.0) of the Python in Ubuntu 14.04.1-
Sylvain Pineau over 9 yearsDo you really need 3.4.2? I'm asking because tk will still be 8.6 on 14.04
-
devGeek over 9 years@SylvainPineau yes, as the Python Official Site quotes "Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes."
-
Sylvain Pineau over 9 yearsI've updated my answer to create the
tkinter
module for your 3.4.2 version built from source.
-
-
Sylvain Pineau over 9 years@devGeek Actually you don't need it for 3.4.0. it's only required to build python from source
-
devGeek over 9 yearsHey, it did work. Runnig,
./python
did work. But, how to make it work usingpython3
in the terminal (by default) -
Sylvain Pineau over 9 years@devGeek to replace your default version with 3.4.2, just run
sudo make install
. It will install 3.4.2 in/usr/local
. Original 3.4.0 is still available with/usr/bin/python3
. -
devGeek over 9 yearsSure, I already did
sudo make install
. Thanks! BTW thepython3
opens 3.4.2 and for 3.4.0python3m
works. -
devGeek over 9 yearsI'm now facing a new problem due to python3.4 error. See, this
-
Eduardo Reis almost 8 yearsAwesome! I use python environment. It is nice to see that a simple make and install solved it, no need to make the environment again.
-
TheWanderer over 7 yearsWhat does this add to the existing, accepted answer?