简体   繁体   English

ubuntu 18.04 上缺少 tkinter package

[英]Missing tkinter package on ubuntu 18.04

This python script has a problem with tkinter but I don't know how to fix it as tkinter is installed, searched on the web but didn't find anything useful这个 python 脚本与tkinter有问题,但我不知道如何修复它,因为tkinter已安装,在 Z2567ZA5EC9705EB18AC2DC9 上搜索但没有发现任何有用的东西

    hp@hp-desktop:~$ python3 predict.py 
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
    import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "predict_stock.py", line 3, in <module>
    import matplotlib.pyplot as plt
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/pyplot.py", line 2372, in <module>
    switch_backend(rcParams["backend"])
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
    import tkinter as Tk
  File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
    import _tkinter
ImportError: No module named '_tkinter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "predict_stock.py", line 3, in <module>
    import matplotlib.pyplot as plt
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/pyplot.py", line 2372, in <module>
    switch_backend(rcParams["backend"])
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "/home/hp/.local/lib/python3.5/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
    import tkinter as Tk
  File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module>
    raise ImportError(str(msg) + ', please install the python3-tk package')
ImportError: No module named '_tkinter', please install the python3-tk package
`

As you can see python3-tk is already installed below `如您所见,python3-tk 已安装在下面

hp@hp-desktop:~$ sudo apt-get install python3-tk
Lettura elenco dei pacchetti... Fatto
Generazione albero delle dipendenze       
Lettura informazioni sullo stato... Fatto
python3-tk è già alla versione più recente (3.6.8-1~18.04).
0 aggiornati, 0 installati, 0 da rimuovere e 0 non aggiornati.

Any idea to fix it?有什么想法可以解决吗? Down here you will find all pip3 whl installed在这里,您会发现所有已安装的 pip3 whl

    hp@hp-desktop:~$ pip3 list
Package                      Version             
---------------------------- --------------------
absl-py                      0.8.0               
alabaster                    0.7.8               
appdirs                      1.4.3               
asn1crypto                   0.24.0              
astor                        0.8.0               
backports.weakref            1.0.post1           
bleach                       2.1.2               
catfish                      1.4.4               
certifi                      2018.1.18           
chardet                      3.0.4               
click                        6.7                 
cloudpickle                  1.2.2               
command-not-found            0.3                 
cryptography                 2.1.4               
cupshelpers                  1.0                 
cycler                       0.10.0              
decorator                    4.1.2               
defer                        1.0.6               
dill                         0.3.0               
distro                       1.4.0               
dlib                         19.15.0             
docutils                     0.14                
entrypoints                  0.2.3.post1         
enum34                       1.1.6               
face-recognition-models      0.3.0               
future                       0.16.0              
gast                         0.3.2               
git-review                   1.26.0              
google-pasta                 0.1.7               
graphsurgeon                 0.2.0               
grpcio                       1.24.0              
gym                          0.14.0              
h5py                         2.10.0              
httplib2                     0.9.2               
idna                         2.6                 
imagesize                    0.7.1               
ipykernel                    4.8.2               
ipython                      5.5.0               
ipython-genutils             0.2.0               
ipywidgets                   6.0.0               
jeepney                      0.4.1               
Jinja2                       2.10                
joblib                       0.13.2              
jsonschema                   2.6.0               
jupyter-client               5.2.2               
jupyter-core                 4.4.0               
Keras                        2.3.0               
Keras-Applications           1.0.8               
Keras-Preprocessing          1.1.0               
keyring                      19.2.0              
kiwisolver                   1.1.0               
language-selector            0.1                 
launchpadlib                 1.10.6              
lazr.restfulclient           0.14.2              
lazr.uri                     1.0.3               
lightdm-gtk-greeter-settings 1.2.2               
lxml                         4.4.1               
Mako                         1.0.7               
Markdown                     3.1.1               
MarkupSafe                   1.0                 
matplotlib                   3.0.3               
menulibre                    2.2.0               
mistune                      0.8.3               
mock                         3.0.5               
mugshot                      0.4.0               
nbconvert                    5.3.1               
nbformat                     4.4.0               
notebook                     5.2.2               
numpy                        1.17.2              
oauth                        1.0.1               
oauthlib                     3.1.0               
onboard                      1.4.1               
openshot-qt                  2.4.1               
opt-einsum                   3.0.1               
pandas                       0.24.2              
pandas-datareader            0.8.1               
pandocfilters                1.4.2               
pbr                          5.4.3               
pexpect                      4.2.1               
pickleshare                  0.7.4               
Pillow                       5.1.0               
pip                          19.2.3              
progressbar2                 3.46.1              
prompt-toolkit               1.0.15              
protobuf                     3.9.2               
psutil                       5.4.2               
py                           1.4.34              
pycairo                      1.16.2              
pycrypto                     2.6.1               
pycups                       1.9.73              
pycurl                       7.43.0.1            
pyglet                       1.3.2               
Pygments                     2.2.0               
pygobject                    3.26.1              
pyparsing                    2.4.2               
pytest                       3.2.3               
python-apt                   1.6.4               
python-dateutil              2.6.1               
python-magic                 0.4.16              
python-utils                 2.3.0               
pytools                      2017.6              
pytz                         2018.3              
pyxdg                        0.25                
PyYAML                       3.12                
pyzmq                        16.0.2              
qtconsole                    4.3.1               
requests                     2.18.4              
requests-unixsocket          0.1.5               
roman                        2.0.0               
scipy                        1.1.0               
screen-resolution-extra      0.0.0               
SecretStorage                3.1.1               
sessioninstaller             0.0.0               
setuptools                   41.2.0              
simplegeneric                0.8.1               
simplejson                   3.13.2              
six                          1.11.0              
Sphinx                       1.6.7               
sphinx-rtd-theme             0.2.4               
ssh-import-id                5.7                 
systemd-python               234                 
tb-nightly                   1.15.0a20190806     
tensorboard                  1.14.0              
tensorflow                   2.0.0rc0            
tensorflow-estimator         1.14.0              
tensorflow-gpu               2.0.0rc1            
tensorrt                     4.0.1.6             
termcolor                    1.1.0               
terminado                    0.7                 
testpath                     0.3.1               
testresources                2.0.1               
tf-estimator-nightly         1.14.0.dev2019080601
tf-nightly-gpu               1.15.0.dev20190821  
tornado                      4.5.3               
tqdm                         4.36.1              
traitlets                    4.3.2               
ubuntu-drivers-common        0.0.0               
uff                          0.4.0               
ufw                          0.36                
unattended-upgrades          0.1                 
urllib3                      1.22                
vboxapi                      1.0                 
wadllib                      1.3.3               
wcwidth                      0.1.7               
webencodings                 0.5                 
Werkzeug                     0.16.0              
wheel                        0.30.0              
wrapt                        1.11.2              
xkit                         0.0.0   

` It seems to work only with python 3.6 ` 它似乎只适用于 python 3.6

ImportError: No module named '_tkinter', please install the python3-tk package
hp@hp-desktop:~$ python3.5 predict_stock.py 
python3.5          python3.5m         python3.6          python3.6-config   python3.6m         python3.6m-config  
hp@hp-desktop:~$ python3.5 predict_stock.py 
python3.5          python3.5m         python3.6          python3.6-config   python3.6m         python3.6m-config  
hp@hp-desktop:~$ python3.5 predict_stock.py 
python3.5          python3.5m         python3.6          python3.6-config   python3.6m         python3.6m-config  
hp@hp-desktop:~$ python3.6 predict_stock.py 
Using TensorFlow backend.

Nope没有

hp@hp-desktop:~$ sudo apt-get install python*.*-tk
Lettura elenco dei pacchetti... Fatto
Generazione albero delle dipendenze       
Lettura informazioni sullo stato... Fatto
Nota, viene selezionato "python2.4-tk" per l'espressione glob "python*.*-tk"
Nota, viene selezionato "python3.7-tk" per l'espressione glob "python*.*-tk"
Nota, viene selezionato "python2.7-tk" per l'espressione glob "python*.*-tk"
Nota, viene selezionato "python2.3-tk" per l'espressione glob "python*.*-tk"
Nota, viene selezionato "python3.6-tk" per l'espressione glob "python*.*-tk"
Nota, viene selezionato "python-tk" al posto di "python2.7-tk"
Nota, viene selezionato "python3-tk" al posto di "python3.6-tk"
Nota, viene selezionato "python3-tk" al posto di "python3.7-tk"
python-tk è già alla versione più recente (2.7.16-2~18.04).
python3-tk è già alla versione più recente (3.6.8-1~18.04).
0 aggiornati, 0 installati, 0 da rimuovere e 0 non aggiornati.
3 non completamente installati o rimossi.
Dopo quest'operazione, verranno occupati 0 B di spazio su disco.
Continuare? [S/n] s
Configurazione di update-notifier-common (3.192.1.7)...
Traceback (most recent call last):
  File "/usr/lib/update-notifier/package-data-downloader", line 24, in <module>
    import debian.deb822
ImportError: No module named 'debian'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/update-notifier/package-data-downloader", line 24, in <module>
    import debian.deb822
ImportError: No module named 'debian'
dpkg: errore nell'elaborare il pacchetto update-notifier-common (--configure):
 il sottoprocesso installato pacchetto update-notifier-common script post-installation ha restituito lo stato di errore 1
dpkg: problemi con le dipendenze impediscono la configurazione di update-notifier:
 update-notifier dipende da update-notifier-common (= 3.192.1.7); tuttavia:
  Il pacchetto update-notifier-common non è ancora configurato.

dpkg: errore nell'elaborare il pacchetto update-notifier (--configure):
 problemi con le dipendenze - lasciato non configurato
dpkg: problemi con le dipendenze impediscono la configurazione di update-manager:
 update-manager dipende da update-notifier; tuttavia:
  Il pacchetto update-notifier non è ancora configurato.

dpkg: errore nell'elaborare il pacchetto update-manager (--configure):
 problemi con le dipendenze - lasciato non configurato
Segnalazione apport non scritta poiché il messaggio di errore indica la presenza di un fallimento precedente.
                                                                                                             Segnalazione apport non scritta poiché il messaggio di errore indica la presenza di un fallimento precedente.
                                                                                                                                                                                                                          Si sono verificati degli errori nell'elaborazione:
 update-notifier-common
 update-notifier

You should install the version of the system package appropriate for the version of Python you are using (3.5).您应该安装适合您正在使用的 Python 版本的系统 package 版本 (3.5)。 Try:尝试:

sudo apt-get install python3.5-tk

You are confused by the output of pip3 list command because it is referring to the default python in your system (which seems to be version 3.6).您对pip3 list命令的 output 感到困惑,因为它指的是系统中的默认python (似乎是 3.6 版)。 To check modules installed for the version you are using to run the script try:要检查为您用于运行脚本的版本安装的模块,请尝试:

pip3.5 list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM