Reputation: 6247
I work with linux on a servies. And I don't have the root privilege. I installed the python-3.2.3 locally to "/home/sam/install_sam". when I import the tkinter module. I get the following error:
ImportError: No module named _tkinter, please install the python-tk package
I know I need to install the Tkinter module. because I don't have the root privilege. I can't use like the following commands:
apt-get install python-tk
sudo apt-get install python-tk
And I search on goolge. I get tcl/tk from here. I install them use the following commands.
cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/tcl
make
make install
cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/tk
--with- tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install
cd ~/Downloads/Python3.2.3/
export LD_LIBRARY_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
export LD_RUN_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
./configure --prefix=/home/sam/install_sam/python
make
make install
I still got error: INFO: Can't locate Tcl/Tk libs and/or headers. How should I config the tcl/tk for the python
Upvotes: 13
Views: 18617
Reputation: 1050
For CentOS, this is:
yum install -y tcl-devel tk-devel
Worked on CentOS 7.
In general, I find that where RHEL has *-dev
, CentOS has *-devel
Upvotes: 1
Reputation: 6687
In my case I had import tkinter
properly working on my Python3 environment, but I had to use a pre-compiled Python with its own environment (Blender fyi) that didn't include the dependencies (I needed tkinter to run matplotlib
).
The fix in my case was very simple:
In the working python, import tkinter
and check where it is installed with tkinter.__file__
. This will be something like path/to/site-packages/tkinter
Copy the tkinter
folder into the site-packages
of your target installation
Then import _tkinter
won't work. Again using the file trick, locate the missing .so
file, in my Ubuntu was something like `path/to/python3.7/lib-dynload/_tkinter.cpython-37m-x86_64-linux-gnu.so'
Again, copy the .so
file into the corresponding lib-dynload
of your target installation. Make sure that both origin and target Python versions are compatible.
To make sure that your target python finds the copied files, make sure that the destination paths are listed under sys.path
.
Hope this helps!
Cheers,
Andres
Upvotes: 0
Reputation: 2573
sudo apt-get install tcl-dev tk-dev
worked for me, although I ended up pulling a docker image and using that instead.
Upvotes: 2
Reputation: 162
Use CPPFLAGS environment variable to set the include directories for tcl and tk before building Python 3. This has worked for me.
export CPPFLAGS="-I/home/sam/install_sam/tcl/include -I/home/sam/install_sam/tk/include"
Upvotes: 7
Reputation: 6247
Finally. I install tcl/tk and python in a same path. It can work now. the commands as follow:
cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/python3
make
make install
cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/python3
--with-tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install
export LD_LIBRARY_PATH=/home/sam/install_sam/python3/lib
cd ~/Downloads/Python3.2.3/3
./configure --prefix=/home/sam/install_sam/python3
make
make install
someone can tell me how to config the tcl/tk for python in the first way(mentioned in the question). I'll appreciate it
Upvotes: 7