Install and make tkinter work on AWS EC2 instance

匿名 (未验证) 提交于 2019-12-03 02:31:01

问题:

I am desperately trying to make tkinter work on my EC2 instance.

I just want to be able to execute this line in python:

from tkinter import * 

or this one for older version as from what I understood before python 3.x you had to use a capital T

from Tkinter import *

Right now both these commands return this:

ImportError: No module named _Tkinter

Here are the steps I took and what I found in my research:

  • The python version currently running on my instance is python 2.6.8, thinking that tkinter might not come with this version I decided to install python version to 3.2 (keeping 2.6.8) using this http://www.hosting.com/support/linux/installing-python-3-on-centosredhat-5x-from-source/

  • Then running python 3.2 I ran in the same problem it tells me no module called tkinter.

  • I then tried to install tkinter using a lot of different commands:

    yum install tkinter

    yum install Tkinter

    yum install python-tk

    yum install python3-tk

    yum install tk-devel

    yum install gtk2-devel

    yum install pygtk2-devel

All of these give me the same result:

No package (name of the package) available.

Also in my python 3.2 folder in /opt (the second one I have installed) there is a folder called tkinter but it still seems that somehow python3 does not see it.

What am I missing? Whys can't I import tkinter when I am in python?

回答1:

Tkinter requires a display. Unless you can somehow access a desktop on the AWS instance, you won't be able to load tkinter, much less use it.



回答2:

After the previous answers I realized why it was not working so I made it work using an EC2 Ubuntu instance and doing the following:

  export DEBIAN_FRONTEND=noninteractive   sudo -E apt-get update   sudo -E apt-get install -y ubuntu-desktop   sudo add-apt-repository ppa:freenx-team   sudo apt-get update   sudo aptitude install -y freenx   wget https://bugs.launchpad.net/freenxserver/+bug/576359/+attachment/1378450/+files/nxsetup.tar.gz   tar -xvf nxsetup.tar.gz   sudo cp nxsetup /usr/lib/nx/nxsetup   sudo /usr/lib/nx/nxsetup --install 

Then said no when asked for a password and did:

  sudo vi /etc/ssh/sshd_config and set PasswordAuthentication to yes   sudo /etc/init.d/ssh restart   sudo passwd ubuntu   sudo apt-get install gnome-session-fallback

Once this was done I installed NX client on my local machine. All this thanks to this page

Connected to my new server where I was able to install python-tk like that:

 sudo apt-get install python-tk

And now I can use tkinter on my instance :)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!