Install tkinter in python3.6 on Ubuntu - python

+--------+-----------------------------------+
| OS | Ubuntu 12.04 |
+--------+-----------------------------------+
| Python | 2.7, 3.2 and source installed 3.6 |
+--------+-----------------------------------+
Since there are 2 versions of Python 3, anything installed from the repository doesn't work for Python 3.6. The latest version of Python in the repositories is 3.2, so I need source installs or through pip3.6.
After starting python3.6 I tried to import tkinter, which gave the following error. Even though help('modules') returned a list of modules which included tkinter.
import tkinter
ModuleNotFoundError: No module named '_tkinter'
I tried doing the same in python3.2 and there were no errors. tkinter._tkinter gave the location of tkinter library for python3.2
I cd'd into the python3.6 directory which has all library files and indeed it was missing the tkinter.so object file.
How do I fix the error?
I would like to get tkinter/tkagg working as it seems all the modules/ package are already installed.
After googling some more, I found I need to build python3.6 again, but this time with Tcl/Tk options while running configure. I'd rather not. It takes 1hr approx to install python3.6 from scratch.
Is there some other way where I can tell python3.6 where Tcl/Tk is located?
The problem isn't telling python where tcl/tk is. After messing around with python3.6's source code, and then comparing python3.6 with python3.2, I found out that tkinter calls _tkinter which isn't a python file, it's an .so(shared object) file that python builds during installation via setup.py that uses gcc, that somehow may involve distutils.
The new and more appropriate question is how do I build,
_tkinter.cpython-36m-i386-linux-gnu.so from tcl/tk?
Note : I do have tcl/tk installed, which I have confirmed using tclsh and wish.

run from terminal:
sudo apt-get install python3.6-tk
or just reinstall completly:
sudo apt-get install python3.6

Python version 3.6.4 (Ubuntu 18.04 LTS)
sudo add-apt-repository main
sudo apt-get install python3-tk

I faced a similar problem to yours, I am giving the details of it and how I solved it.
On Ubuntu 16.04 LTS, I have Python 3.5.2 and Python 2.7.12 but I would like to experiment Python3.6 (for various reasons like this one, for example). So I relied on this post:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
When I tried to run a module using tkinter, I got this error message:
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 37, in <module>
import _tkinter
ModuleNotFoundError: No module named '_tkinter'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "bill.py", line 3, in <module>
from tkinter import Canvas, Label, Tk, StringVar, Button, LEFT
File "/usr/lib/python3.6/tkinter/__init__.py", line 39, in <module>
raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
I tried to install tkinter as the message above asks:
sudo apt-get install python3-tk
[sudo] password for begueradj:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.5.1-1).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Obviously, I still can not use tkinter for Python 3.6. How to fix this problem?
My first blind attempt did not work:
sudo apt-get install python36-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python36-tk
The second one works:
sudo apt-get install python3.6-tk
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
tix python3.6-tk-dbg
The following NEW packages will be installed:
python3.6-tk
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 74.6 kB of archives.
After this operation, 165 kB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial/main amd64 python3.6-tk amd64 3.6.5-1+xenial1 [74.6 kB]
Fetched 74.6 kB in 0s (301 kB/s)
Selecting previously unselected package python3.6-tk:amd64.
(Reading database ... 324106 files and directories currently installed.)
Preparing to unpack .../python3.6-tk_3.6.5-1+xenial1_amd64.deb ...
Unpacking python3.6-tk:amd64 (3.6.5-1+xenial1) ...
Setting up python3.6-tk:amd64 (3.6.5-1+xenial1) ...
And that solved my problem:
~/python3.6
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>>

Python version 3.6.4 (Ubuntu 18.04 LTS)
I was having the same error: tkinter module not found. Even after trying to install via pip
$ pip install tkinter
I got this error, below
Collecting tkinter
Could not find a version that satisfies the requirement tkinter (from versions: )
No matching distribution found for tkinter
I did this tried to install tkinter for Python3.6 by running the command. It worked for me.
$ sudo apt-get install python3.6-tk

Installed python3.8.2 on ubuntu 20.04, tried importing tkinter but failed. Got this error:
da0xxx:~/python_trn/pygui$ python3 -m tkinter
/usr/bin/python3: No module named tkinter
but ran:
da0xxx:~/python_trn/pygui$ sudo apt-get install python3-tk
now able to import tkinter!
da0xxx:~/python_trn/pygui$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import tkinter as tk
Thanks above!

Try these lines, It might help
os.environ['TCL_LIBRARY'] = r'C:\Users\asus\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\asus\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
Recheck path before executing.

Related

import jwt ImportError: No module named jwt

I have been trying to run this project
https://github.com/udacity/FSND-Deploy-Flask-App-to-Kubernetes-Using-EKS
I installed all the dependencies.
I still did not make any adjustments. I need to run it first
but I get this error when I type the command
python main.py
this is the error i get:
Traceback (most recent call last):
File "main.py", line 8, in <module>
import jwt
ImportError: No module named jwt
I worked with similar errors before and managed to solve them but not with this one I could not figure out the source of the problem
Check if PyJWTY is in the requirements file or if is installed in you system, using: pip3 install PyJWT
You could also face this error if you have running on your machine two versions of python. So the correct command will be python3 main.py
I have hit the same issue with pyjwt 2.1.0 which was clearly installed in my venv as well as globally. What helped was to downgrade it to version 1.7.1
pip install "PyJWT==1.7.1"
run the app and then to reinstall newest version 2.1.0
pip install "PyJWT==2.1.0"
And the issue disappeared.
This project has requirements that need to be installed for it to work. These can be installed via pip, pip install -r requirements.txt (I've linked to the requirements file in the project), which you can read more about here.
What worked for me was using import jwt instead of import PyJWT. I am using version PyJWT-2.3.0.
jwt image on vscode
As you can see no errors in the above screenshot. The app runs without import errors.
Image of terminal
Faced the same issue. Am using a guest VM running ubuntu 16.04.
I have multiple versions of python installed - both 3.5 and 3.7.
After repeated tries with and without using virtualenv what worked finally is:
Create a fresh virtual environment using :
priya:~$ virtualenv -p /usr/bin/python3.7 fenv
Activate the virutal environment :
priya:~$ source ./fenv/bin/activate
Note : You can find the path for python3.7 by using whereis python:
priya:~$ whereis python
python: /usr/bin/python /usr/bin/python3.5m /usr/bin/python3.5 /usr/bin/python3.7 /usr/bin/python3.5m-config /usr/bin/python3.5-config /usr/bin/python2.7 /usr/bin/python3.7m /usr/bin/python2.7-config /usr/lib/python3.5 /usr/lib/python3.7 /usr/lib/python2.7 /etc/python /etc/python3.5 /etc/python3.7 /etc/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python3.7 /usr/local/lib/python2.7 /usr/include/python3.5m /usr/include/python3.5 /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
Referenced link is : https://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv#:~:text=By%20default%2C%20that%20will%20be,%2Flocal%2Fbin%2Fpython3
For your project - FSWD Nanodegree -
After you have activated your virtualenv, run pip install -r requirements.txt
You can test by :
(fenv) priya:FSND-Deploy-Flask-App-to-Kubernetes-Using-EKS :~$ python
Python 3.7.9 (default, Aug 18 2020, 06:24:24)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
import jwt
exit()
pip3 install flask_jwt_ex.. I was doing this without sudo. And then I was working on the program as sudo.
You have to have only PyJWT installed and not JWT. Make sure you uninstall JWT (pip uninstall JWT) and install PyJWT (pip install PyJWT)

Can't import PyQt5 on Raspberry Pi with Python 3.6.5

I am attempting to run a small PyQt application on a Raspberry Pi with jesse but cannot get the PyQt5 module to import in Python 3.6
pi#raspberrypi:~ $ cat /etc/debian_version
8.0
pi#raspberrypi:~ $ python3 --version
Python 3.6.5
pi#raspberrypi:~ $ sudo apt-get install python3-pyqt5
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pyqt5 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
pi#raspberrypi:~ $ sudo apt-get install pyqt5-dev-tools qttools5-dev-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
pyqt5-dev-tools is already the newest version.
qttools5-dev-tools is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
pi#raspberrypi:~ $ python3
Python 3.6.5 (default, Jul 4 2019, 01:11:28)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5'
>>>
Is my import statement wrong? Is the package named something else?
No, your import statement is not wrong. No, the (apt or pip) package is not named something else. However, Python 3.6.5 is not the Python 3 version that shipped with Debian Jessie — that's Python 3.4.2.

ImportError: No module named 'ase.build'

In ubuntu 16.04 i installed python and modules:
sudo apt install python3 python3-scipy python3-numpy python3-ase
then i try to follow the first tutorial on the ASE homepage. I run python3 in bash terminal, and can import other modules but not ase-build. It looks like this:
>>> from ase.optimize import QuasiNewton
>>> from ase.build import fcc111, add_adsorbate
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'ase.build'
>>>
Using a python script throws an equivalent error.
What could be the problem?
UPDATE & SOLUTION
Seems this was not really even a python problem. I seem to have had some package dependency errors probably due to not running apt update in a long time between program installations. I removed python2.x and python 3.x, then iterated apt update, apt upgrade, apt autoremove, then reinstalled only python3. I installed python3-pip and installed the numpy, scipy, and ase packages using the proper form python3 -m pip install --upgrade <package>. Now everything works as expected.
Check what version of the library you have.
import ase
print(ase.__version__)
If the version is 3.10.0 then that is the problem since the build module appeared (as far as I know) in the 3.11.0 version.
Due to this link - you have installed the 3.9.1.4567-3 version on your computer.
But The asu.build has been added in:
commit 71c9563e423e2add645c26f8d0a722f3db13e135
Author: Jens Jørgen Mortensen
Date: Tue Apr 12 15:40:59 2016 +0200
Move stuff to ase.build module
So, the module asu.build doesn't exist in your version (3.9 has been released in 2015). You have to install the newer version of python3-asu.

No module named main, wkhtmltopdf issue

I'm new in python, but all search results i found was useless for me.
C:\Users\Aero>pip install wkhtmltopdf
Collecting wkhtmltopdf
Using cached wkhtmltopdf-0.2.tar.gz
Installing collected packages: wkhtmltopdf
Running setup.py install for wkhtmltopdf
Successfully installed wkhtmltopdf-0.2
C:\Users\Aero>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wkhtmltopdf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\wkhtmltopdf\__init__.py", line 1, in <module>
from main import WKhtmlToPdf, wkhtmltopdf
ImportError: No module named 'main'
That is happening all the time. Thanks for any help.
Update:
I find that installing Python 2.* makes it okay, cause of main module isn't correct while using print (Using 2.* version).
But i still want to know, it there any ways?
i solve it installing it this way, i hope it work for you
pip install django-wkhtmltopdf
It wasn't working for me for the first time, but after a PyCharm restart I could see anything. This might work for you: (Tested on Python 3.3.0)
import wkhtmltopdf
from wkhtmltopdf.main import WKhtmlToPdf
var = WKhtmlToPdf(
url='http://www.example.com',
output_file='~/example.pdf',
)
var.render()
If none of the other options work, it might be something wrong with your cache. Try uninstalling wkhtmltopdf and django-wkhtmltopdf and reinstalling without the cache:
pip uninstall django-wkhtmltopdf wkhtmltopdf
pip install --no-cache-dir wkhtmltopdf==0.2
pip install --no-cache-dir django-wkhtmltopdf==3.2.0
(Note that the above wkhtmltopdf and django-wkhtmltopdf version numbers may be different in your case.)
Seems there is some error with package installation of wkhtmltopdf. It wasn't working for me then i uninstalled the package and re-installed it by doing
python -m pip uninstall wkhtmltopdf
and then
python -m pip install wkhtmltopdf
it worked for me.try this it may work.

Ubuntu - Python installations

I have python-2.7.9 installed on my machine and I am trying to install numpy, matplotlib, pyopengl, and pyqt4.
I've installed pyqt4 using the source file and it imports fine when using python, however, i get an error for the remaining packages.... no module named numpy.
I installed numpy and matplotlib using the following commands:
sudo apt-get install python-numpy
sudo apt-get install pyhton-matplotlib
I also tried using pip and aptitude but I still get the same error..im not sure what I am doing wrong or how to fix these issues. Does anyone have any advice?
UPDATE:
Using Ubuntu 14.04.1 LTS
These are the errors I get:
Python 2.7.9 (default, Feb 5 2015, 11:24:57)
[GCC 4.8.2] on linux2
Type "help", "copyright", or "license" for more information.
import numpy
Traceback (most recent call last):
File "", line 1, in
ImportError: Mo module named numpy
In ubuntu 14.04, the packages you want are not called simply numpy and matplotlib. Instead they are python-numpy and python-matplotlib. Thus to install them you need:
sudo apt-get install python-numpy
sudo apt-get install python-matplotlib
EDIT:
Based on the comments below, the issue was a different version of python 2.7than the one provided by Ubuntu. More info in comments. An alias to the ubuntu's python seems to solved the problem.

Categories

Resources