Cannot import tkinter after installing Python 3 with pyenv

后端 未结 3 795
小鲜肉
小鲜肉 2021-01-12 00:58

I got problems with importing tkinter after installing Python version 3.4.2 with pyenv. My system Python is version 2.7.6. I am using Ubuntu 14.04.

相关标签:
3条回答
  • 2021-01-12 01:10

    Change your code to:

    import tkinter
    

    Documentation link:

    Most of the time, tkinter is all you really need, but a number of additional modules are available as well. The Tk interface is located in a binary module named _tkinter. This module contains the low-level interface to Tk, and should never be used directly by application programmers. It is usually a shared library (or DLL), but might in some cases be statically linked with the Python interpreter.

    0 讨论(0)
  • 2021-01-12 01:17

    For MacOS you can try installing tcl-tk via homebrew and then activating the env. vars. mentioned in its caveats section, as detailed in this answer.

    0 讨论(0)
  • 2021-01-12 01:26

    This problem seems to be solved now using the approach described in this post:

    • First uninstall Python 3.4.2 : pyenv uninstall 3.4.2, then
    • Run sudo apt-get install tk-dev
    • And reinstall Python 3.4.2 : pyenv install 3.4.2
    0 讨论(0)
提交回复
热议问题