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.
Related
The error I get is:
No module named '_tkinter'
I have tried using:
sudo apt-get install python python-tk idle python-pmw python-imaging
The turtle works in python2.7.1
You probably only installed the turtle for python 2.7.
sudo apt-get install python3-tk
(and others you may need)
I am trying to use the qrtools module with Python 3.4.2 on my Raspberry Pi 2, however it cannot run as I don't have the zbar module installed.
Trying
pip-3.2 install zbar
Gives the error message shown in the picture
sudo pip-3.2 install zbar
gives a similar error
Any ideas?
(I do have it installed with Python 2.7)
UPDATE: Both libzbar-dev and python3-dev are up to date. Still...
No module named 'zbar'
assuming you're using a debian derivative (like ubuntu), you need to install zbar's developement package, which contains the header file zbar.h
$ sudo apt-get install libzbar-dev
for redhat/fedora systems:
$ sudo yum install zbar-devel
and probably python's dev package too:
$ sudo apt-get install python3-dev
or you can use pip install zbar-py
https://pypi.org/project/zbar-py/
Try the following code after entering sudo mode:
yum install zbar-devel
This should work for fedora.
Bumping #herve solution
On ubuntu and on Mint
sudo apt-get install python-zbar libzbar-dev python-qrtools
pip install libzbar-cffi==0.2.1
I have two python compilers on my Ubuntu 14.04 VM. I have installed matplotlib as
pip install matplotlib
But the matplotlib cannot be used from python3.It can be used from python2.7
If I use import matplotlib.pyplot as plt inside my script test.py and run it as
python3 test.py
I get the error
ImportError: No module named 'matplotlib'
How can this be fixed.
Use pip3 to install it:
sudo apt-get install python3-pip
sudo pip3 install matplotlib
You can install the package from your distro with:
sudo apt-get install python3-matplotlib
It will probably throw an error when you import matplotlib, but it is solved by installing the package tkinter with:
sudo apt-get install python3-tk
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 :)
I just installed it with apt-get on debian linux with
apt-get install libqt4-opengl
the rest of PyQt4 is available, but I cant get to this new module.
from PyQt4 import QtOpenGL
raises ImportError. any idea what to do?
Did you forget to install the Python bindings?
apt-get install python-qt4-gl
For Python3, I had to do sudo apt-get install python3-pyqt4.qtopengl