I'm having a few problems running tkinter on my Puppy Linux laptop using Geany to write and execute the code. I've got Python 3.1 running ok, but whenever I try to
import tkinter
I get the following error message:
file "/usr/lib/python3.1/tkinter/__init__.py", line 40, in <module>
import _tkinter
UnicodeEncodeError: 'latin-1 codec can't encode characters in position 0-3: ordinal not in range(256)
I don't have the foggiest what's going on!
I changed the Geany filetypes.python document from:
compiler=python -m py_compile "%f"
run_cmd=python "5f"
which runs Python2 as the default (tkinter imports fine with this!), to:
compiler=python3.1 -c "import py_compile;py_compile.compile('%f')"
run_cmd=python3.1 "%f"
in order to allow me to use python 3.1 as the default. I did copy this code, rather than writing it as I'm not familiar with Linux.
I would like to know how I can successfully use tkinter with Python3 on PuppyLinux. I'm not tied in to using Geany, so any help is appreciated!
Rich
Related
I wrote a simple script to check the battery time on my laptop (the built in one on xubuntu seems somewhat inaccurate), the code runs fine in a python terminal but when I run it without starting in the python terminal I get an error related to 'import psutil'.
the script is
I'm very inexperienced with python and haven't been able to find anything helpful online.
#!/usr/bin/env python3.6.7
import psutil
import time
a=psutil.sensors_battery()
b=str(a)
c=b[b.rfind(start)+len(start):b.rfind(end)]
d=int(c)/3600
print(d)
time.sleep(130)
exit()
what I expected is the value c divided by 3600 to be printed on the terminal, display for a while and then exit. instead i get
Desktop$ python battery.py
Traceback (most recent call last):
File "battery.py", line 2, in <module>
import psutil
ImportError: No module named psutil
i also tried running through the menu options when i right click the script and select python3.6, where a terminal flashes and closes immediatly (to quickly to read any of the print in it).
i've also changed
#!/usr/bin/env python3
#!/usr/bin/env python3.6
#!/usr/bin/env python3.6.7
each has the same result
thank you for any advice
david
I've been searching for it but could not find anything on the net on this topic.
When I'm working on a programm in python 3.5 which imports tkinter or pyglet I'm perfectly able to start it from the command line on my Linux Mint installation. As soon as I try to start it from pycharm or Visual Studio Code I get an error.
It is for tkinter:
Traceback (most recent call last): File "/home/b...", line 3, in <module>
import tkinter as tk
File "/usr/lib/python3.5/tkinter/__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'
Both, the tkinter and the pyglet script, are working when they are started from idle3 (with F5).
Can anyone help me out?
Best
B.
i'm having the same issue. The problem lie with Linux Mint Software Manager. If your vs code is install via Software Manager, it will be install in Flatpak virtual sandbox. Just download and run vs code from its homepage will do.
I just installed the above mentioned Anaconda version. Jupyter works fine, but I can't launch Spyder as I get
File "/proj/mianxx/anaconda3/lib/python3.6/site-packages/qtpy/QtWebEngineWidgets.py", line 22, in <module>
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ModuleNotFoundError: No module named 'PyQt5.QtWebEngineWidgets'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/proj/mianxx/anaconda3/bin//spyder", line 6, in <module>
sys.exit(spyder.app.start.main())
File "/proj/mianxx/anaconda3/lib/python3.6/site-packages/spyder/app/start.py", line 103, in main
from spyder.app import mainwindow
File "/proj/mianxx/anaconda3/lib/python3.6/site-packages/spyder/app/mainwindow.py", line 92, in <module>
from qtpy import QtWebEngineWidgets # analysis:ignore
File "/proj/mianxx/anaconda3/lib/python3.6/site-packages/qtpy/QtWebEngineWidgets.py", line 26, in <module>
from PyQt5.QtWebKitWidgets import QWebPage as QWebEnginePage
ImportError: /proj/mianxx/anaconda3/lib/python3.6/site-packages/PyQt5/../../../././libgsttag-1.0.so.0: undefined symbol: g_mutex_init
I am too much of a noob to take it from here...Any hints?
I've checked This GIT entry but I can't make much of it. It also seems old, despite being open.
EDIT
The issue appears to be related to tcsh, which is the default shell called.
If one issues
bash
LD_LIBRARY_PATH= spyder
This works and launches spyder correctly. However,
bash
spyder
will generate the same error as above.
Thanks to #Carlos Cordoba for his help.
Thanks for Carlos Cordoba's help, When I try to use:
LD_LIBRARY_PATH= spyder
in terminal, it really works but 'spyder' can't. Then I use:
sudo gedit ~/.bashrc
to open bashrc, write
export LD_LIBRARY_PATH= spyder:$LD_LIBRARY_PATH
save and open terminal with:
source ~/.bashrc
retry enter:
spyder
in terminal, works!
UPDATE
There is still something wrong when I write LD_LIBRARY_PATH= spyder in bashrc, every time when I open terminal, there is an error shows that space shouldn't write before spyder, but when I alter LD_LIBRARY_PATH= spyder into LD_LIBRARY_PATH=spyder, Spyder won't launch again, So there are two ways can solve this problem:
Don't mind see warning every time you open terminal
Use LD_LIBRARY_PATH= spyder open spyder
I found the answer (work with Ubuntu 18.04)
Check the version of pyqt
conda list pyqt
if it is 5.6.x
It won't work so I resorted to this simple command:
conda install pyqt=5.9.2
(and later also to
qt=5.9.5 qtpy=1.4.1 check all with conda list qt)
then you're good to launch spyder
More info on lixun's answer. In fact you may do
$ export LD_LIBRARY_PATH=
$ spyder
and it will work without any warning. Seasoned spyder/qt/anaconda specialists may be able to explain why. I do not feel this is a good solution. It is just a workaround.
I am using anaconda on Ubuntu 16.04.
Hi have been scavenging the web for answers on how to do this but there was no direct answer. Does anyone know how I can find the version number of tkinter?
In Python 3, it's tkinter with a small t, and you need to import it. Thus:
>>> import tkinter
>>> tkinter.TkVersion
8.6
If you didn't import it, you'd get the error you mentioned.
tkinter.TclVersion and tkinter.TkVersion described in other answers provide the major and minor Tcl/Tk versions but not the patch number.
On the other hand, the info patchlevel Tcl command returns the version in the major.minor.patch format.
import tkinter
tcl = tkinter.Tcl()
print(tcl.call("info", "patchlevel"))
# Output:
# 8.6.10
The following should be preferred to call the command from a Tkinter app, which already has an associated Tcl interpreter:
import tkinter
root = tkinter.Tk()
...
print(root.tk.call("info", "patchlevel"))
# Output:
# 8.6.10
Type this command on the Terminal and run it.
python -m tkinter
A small window will appear with the heading tk and two buttons: Click Me! and QUIT. There will be a text that goes like This is Tcl/Tk version ___. The version number will be displayed in the place of the underscores.
You cal so invoke TclVersion:
>>> import tkinter
>>> tkinter.TclVersion
8.6
Tested for Python 3.6.5 and Python 3.5.2 (Ubuntu 16.04.4):
Run Tkinter.TclVersion or Tkinter.TkVersion and if both are not working, try Tkinter.__version__
In the terminal try as follows:
python -m tkinter or python3 -m tkinter
I have encountered difficulty putting pygame together with python3 on my MacBookPro.
I installed Python 3.3, and my MacOS is running version 10.7.5.
Then I downloaded pygamev1.9.1 source code, and followed instructions in http://programming.itcarlow.ie/PyGameInstall.pdf
Compilation and installation was smooth until I issued "import pygame" inside python3.
Then I encountered the following "PyCobJect_AsVoidPtr" error (further text following error message):
import pygame
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/init.py", line 95, in
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/base.so, 2): Symbol not found: _PyCObject_AsVoidPtr
Referenced from: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/base.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/base.so
A search on google indicates this symbol has been removed since Python3.2:
http://mail.python.org/pipermail/python-dev/2011-March/108882.html
Can someone please give me some advice on how to get pygame working on Python3.3?
More so, whereas I am aware the pygame/python3 developers are busy with their work, but I would certainly appreciate it if someone can provide precompiled pygame binaries for python3. I have limited computer skills, and I just want to go ahead and learn Python3 and pygame, and this is seriously stunting my interest.
I notice that you were trying to compile from source, but builds on Python 3.3, to my knowledge, are not yet supported (as of January 2013). In fact, the only binaries I'm aware of for PyGame and Python 3.3 are unofficial builds and Windows only.
You should consider instead using a previous version of Python (e.g. Python 2.7.*), PyGame builds/binaries on which are well-supported. Any points on setting up should be directed to the pygame-users mailing list, if they weren't already.