【问题标题】:brew install python/matplotlib not working: No module named _tkinterbrew install python/matplotlib 不工作:没有名为 _tkinter 的模块
【发布时间】:2015-12-22 21:47:34
【问题描述】:

我正在努力在 matplotlib 中制作基本图。看起来我没有正确安装 tkinter,据我所知应该从 --with-tcl-tk 标志安装。什么可能导致我的错误?我怎样才能更好地诊断这个问题?下载ActiveState tkinter 对我没有帮助。

我卸载然后重新安装了我认为相关的所有内容。 brew 没有引发错误。

$ brew uninstall python
$ brew uninstall matplotlib numpy --force
$ brew install python --with-tcl-tk
$ brew install numpy matplotlib --with-tcl-tk

但是,当我导入 pyplot 时出现错误:

$ python
Python 2.7.11 (default, Dec 22 2015, 12:47:31) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from matplotlib import pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 109, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
    from six.moves import tkinter as Tk
  File "/usr/local/lib/python2.7/site-packages/six.py", line 199, in load_module
    mod = mod._resolve()
  File "/usr/local/lib/python2.7/site-packages/six.py", line 113, in _resolve
    return _import_module(self.mod)
  File "/usr/local/lib/python2.7/site-packages/six.py", line 80, in _import_module
    __import__(name)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
>>> 

【问题讨论】:

    标签: homebrew pythonbrew


    【解决方案1】:

    这比卸载方法快一点(希望更安全)...

    1) 确保您已安装 Brew 的 Tcl/Tk(它与 MacOS 分开)

    brew install tcl-tk
    

    2) 现在重新编译启用 Tcl/Tk 的 Python

    brew reinstall python --with-tcl-tk
    

    【讨论】:

    • 我认为 brew reinstall python --with-tcl-tk 在带有 tcl-tk 8.6.9 的 Homebrew 2.1.10 中失败。有可能吗?
    【解决方案2】:

    就我而言,我通过使用自制软件卸载并重新安装 Python 解决了这个问题。我希望有更好的解决方案,其他人可以提供...

    $ brew uninstall python@2
    Uninstalling /usr/local/Cellar/python@2/2.7.14_3... (4,324 files, 77.4MB)
    $ brew install python@2
    ==> Downloading https://homebrew.bintray.com/bottles/python@2-2.7.14_3.el_capita
    ######################################################################## 100.0%
    ==> Pouring python@2-2.7.14_3.el_capitan.bottle.2.tar.gz
    ==> /usr/local/Cellar/python@2/2.7.14_3/bin/python -s setup.py --no-user-cfg ins
    ==> /usr/local/Cellar/python@2/2.7.14_3/bin/python -s setup.py --no-user-cfg ins
    ==> /usr/local/Cellar/python@2/2.7.14_3/bin/python -s setup.py --no-user-cfg ins
    ==> Caveats
    Pip and setuptools have been installed. To update them
      pip install --upgrade pip setuptools
    
    You can install Python packages with
      pip install <package>
    
    They will install into the site-package directory
      /usr/local/lib/python2.7/site-packages
    
    See: https://docs.brew.sh/Homebrew-and-Python
    ==> Summary
    ?  /usr/local/Cellar/python@2/2.7.14_3: 4,669 files, 82.4MB
    

    Pip 保留了一切,我使用的 venv 也完好无损。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 2021-04-09
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多