Install and make tkinter work on AWS EC2 instance - python

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?

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.

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 :)

Related

upgrade python offline - ubuntu apt

I have an Ubuntu VM without internet access. It currently has Python 3.10 installed but I want to update to Python 3.11 (the latest at the time of this post).
On a machine with internet access, I used apt to download Python3.11.
mkdir python_3.11
apt-get --download-only -o Dir::Cache="./python_3.11/" -o Dir::Cache::archives="./python_3.11/" install python3.11
$ ls python_3.11
libpython3.11-minimal_3.11.0~rc1-1~22.04_amd64.deb pkgcache.bin
libpython3.11-stdlib_3.11.0~rc1-1~22.04_amd64.deb python3.11-minimal_3.11.0~rc1-1~22.04_amd64.deb
lock python3.11_3.11.0~rc1-1~22.04_amd64.deb
partial srcpkgcache.bin
After transferring the files onto the VM, I tried running sudo dpkg -i on each of the files. This eventually "installed" them but opening a python shell still shows the old 3.10 version. /usr/bin/python3 still points to /usr/bin/python3.10 and this is no /usr/bin/python3.11.
Another thing I've tried
# on the machine im trying to install
sudo apt-get update -oDir::Cache::archives="/path/to/downloaded/packages" --no-install-recommends --no-download
sudo apt-get -oDir::Cache::archives="/path/to/downloaded/packages" --no-install-recommends --no-download install python3.11-minimal
This ends up returning
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
I've since added the following to the download command. python3.11-minimal libpython3.11-stdlib python3.11 libpython3.11-minimal python3.11-venv python3.11-doc binfmt-support python3-pip-whl python3-setuptools-whl. During the install, I'm still getting the same error message on "Unable to fetch some archives".
There are 2 commands that need to be run. I'm not 100% sure the first one (the update) is necessary. It is important that the paths are absolute. Assuming the required packages have been downloaded, it should install.
apt-get -oDir::Cache::archives="/absolute/path/" -oDir::Cache="/absolute/path" --no-install-recommends --no-download update
apt-get -oDir::Cache::archives="/absolute/path/" -oDir::Cache="/absolute/path/" --no-install-recommends --no-download install python3.11

How do I install tkinter on RedHat?

I am trying to install tkinter on Redhat 7.7. I have tried every combination if "sudo yum install [whatever]" and every single time it comes up with "No package [whatever] available".
pip install tkinter
pip3 install tkinter
sudo yum install python3-tkinter
sudo yum install tkinter
sudo yum install python36-tkinter
sudo yum -y install python36u-tkinter
sudo yum -y install python36-tkinter
sudo yum install tkinter
sudo yum install python36-tkinter
sudo yum install python35-tkinter.x86_64
...etc
I have tried to find what repository I might need to enable but RedHat support is all behind a pay wall. What repository do I need to enable?
At this point I am actually considering just switching to Ubuntu as RedHat is giving me all sorts of problems.
EDIT: I tried yum search tkinter and got the following:
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
manager
Repo rhel-7-workstation-rpms forced skip_if_unavailable=True due to:
/etc/pki/entitlement/4690243650278863397-key.pem
====================== Matched:tkinter==========================
python3.x86_64 : Interpreter of the Python programming language
I already have python3 installed. I don't know if had I installed via sudo yum install python3.x86_64 vs sudo yum install python3 I would have got different results.
This works for me!
sudo yum search tkinter
sudo yum install python3-tkinter.x86_64
Alright, so I managed to fix this to my satisfaction. What I did is outlined here. First I installed ActiveState's ActiveTcl 8.5, then rebuilt python 3.6 manually by downloading the source using the following:
$: ./configure --with-tcltk-includes='-I/opt/ActiveTcl-8.5/include'
--with-tcltk-libs='/opt/ActiveTcl-8.5/lib/libtcl8.5.so /opt/ActiveTcl-
8.6/lib/libtk8.5.so'
$: make
$: make install
Because I had a couple different versions of Python 3.x, I had to add the following to the .bashrc:
export PYTHONPATH=/usr/local/lib/python36.zip:/usr/local/lib/python3.6:/usr/local/lib/python3.6/lib-dynload:/usr/local/lib/python3.6/site-packages:/usr/local/lib64/python3.6/site-packages
One big issue I ran into was first manually installing Python 3.8 (which came out yesterday) for which there seems to be little support for most packages so far, so be advised. I also had a few system-specific issues with pip.

"E: Unable to locate package python-pip" on Ubuntu 18.04 [duplicate]

This question already has answers here:
Unable to install pip in ubuntu?
(2 answers)
Closed 1 year ago.
I am trying to install virtualenv on Ubuntu.
First it said command 'pip' not found, so I typed
sudo apt install python-pip
then it said
E: Unable to locate package python-pip
I tried to reset WSL, download using cmd but it doesn't work with Ubuntu. I don't know why. Even though I have downloaded python3, virtualenv, and pip using cmd. It doesn't work with Ubuntu 18.04. It also fails on Ubuntu 14.04.
aiki#LAPTOP-886AEJJG:~$ pip
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
aiki#LAPTOP-886AEJJG:~$ sudo apt install python-pip
[sudo] password for aiki:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-pip
I'm trying to install jarvis and mycroft on win 10, but I need to use Ubuntu because it only works with Linux.
ls /bin/python*
Identify the highest version of python listed.
If the highest version is something like python2.7 then install python2-pip
If its something like python3.8 then install python3-pip
Example for python3.8:
sudo apt-get install python3-pip
Try following command sequence on Ubuntu terminal:
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install python3-pip
Try the following commands in terminal, this will work better:
apt-get install curl
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python get-pip.py
On some kind of Linux, like distros based on Debian, you might want to consider updating your 'apt-get' first, in case you are installing python-pip through it.
sudo apt-get update
This might help apt-get to update its indexes and locate the python-pip package.
After this, u might install it like this-
sudo apt-get install python-pip (Python2)
sudo apt-get install python3-pip (Python3)
You might have python 3 pip installed already. Instead of pip install you can use pip3 install.
To solve the problem of:
E: Unable to locate package python-pip
you should do this. This works with the python2.7 and you not going to get disappointed by it.
follow the steps that are mention below.
go to get-pip.py and copy all the code from it.
open the terminal using CTRL + ALT +T
vi get-pip.py
paste the copied code here and then exit from the vi editor by pressing
ESC then :wq => press Enter
lastly, now run the code and see the magic
sudo python get-pip.py
It automatically adds the pip command in your Linux.
you can see the output of my machine
I'm using WSL2 on Windows 10 and I had the same issue. Try the way which helped me to fix this. I assume that you are using python3.
python3 get-pip.py
sudo apt install python3-pip

Getting wxPython with Ubuntu 16.04 and using it with Pycharm

I'm trying to make a window with wxPython, but trying to install it into the project interpreter in my Pycharm project doesn't work. I then tried installing it onto my computer, but that didn't work either. I've read that wxPython is not very compatible with Linux, so I'm drawing a blank. How do I get wxPython onto Ubuntu 16.04 and then allow me to use Pycharm in order to make the window?
You can get an old version of wxPython using apt-get. Something like this should work:
sudo apt-get install python-wxgtk3.0
or
sudo apt-get install python-wxgtk2.8
But if you want the latest wxPython, you can use pip:
pip install wxPython
I highly recommend installing the latest version, which is wxPython 4.
Add the repository and update package list
echo "deb http://archive.ubuntu.com/ubuntu wily main universe" | sudo tee /etc/apt/sources.list.d/wily-copies.list
sudo apt update
sudo apt install python-wxgtk2.8
sudo rm /etc/apt/sources.list.d/wily-copies.list
sudo apt update
done...
working on Raspberry pi also.

Installing tkinter on ubuntu 14.04

I want to run python code on Ubuntu 14.04, but when I execute it, it gives me the following error message
Traceback (most recent call last):
File "main.py", line 2, in <module>
from tkinter import *
ImportError: No module named tkinter
Try writing the following in the terminal:
sudo apt-get install python-tk
Don't forget to actually import Tkinter module at the beginning of your program:
import Tkinter
If you're using Python 3 then you must install as follows:
sudo apt-get update
sudo apt-get install python3-tk
Tkinter for Python 2 (python-tk) is different from Python 3's (python3-tk).
To get this to work with pyenv on Ubuntu 16.04, I had to:
$ sudo apt-get install python-tk python3-tk tk-dev
Then install the version of Python I wanted via pyenv:
$ pyenv install 3.6.2
Then I could import tkinter just fine:
import tkinter
First, make sure you have Tkinter module installed.
sudo apt-get install python-tk
In python 2 the package name is Tkinter not tkinter.
from Tkinter import *
ref: http://www.techinfected.net/2015/09/how-to-install-and-use-tkinter-in-ubuntu-debian-linux-mint.html
Try:
sudo apt-get install python-tk python3-tk tk-dev
If you're using python3, then Python3 virtual environment(venv) is also required. Use:
sudo apt install python3-venv
Install the package python-tk like
sudo apt-get install python-tk
That is described (with apt-cache search python-tk as)
Tkinter - Writing Tk applications with Python
In Ubuntu 14.04.2 LTS:
Go to Software Center and remove "IDLE(using Python-2.7)".
Install "IDLE(using Python-3.4)".
Try again. This step worked for me.

Categories