tkinter looks installed, but fails when imported

已完成

I really want to use matplotlib > 3.8.4, but it requires this solution which is not working.

My configuration:

PyCharm 2024.3 (Community Edition)
Build #PC-243.21565.199, built on November 12, 2024
Runtime version: 21.0.5+8-b631.16 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 14.6.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 12
Metal Rendering is ON
Registry:
 debugger.new.tool.window.layout=true
 ide.experimental.ui=true
 i18n.locale=
 python.debugger.use.dispatcher=true
Non-Bundled Plugins:
 me.lensvol.blackconnect (0.6.2)
 com.jetbrains.space (243.21565.122)
 org.jetbrains.plugins.gitlab (243.21565.204)

The issue is that when matplotlib > 3.8.4, this statement

import tkinter

 when executed in python 3.12 throws this error:

 File "~/.pyenv/versions/3.12.1/lib/python3.12/tkinter/__init__.py", line 38, in <module>

   import _tkinter # If this fails your Python may not be configured for Tk

   ^^^^^^^^^^^^^^^

ModuleNotFoundError: No module named ‘_tkinter’

However, it appears to be installed, as per the output of

brew install python-tk@3.12

==> Downloading https://formulae.brew.sh/api/formula.jws.json

################################################################################################################################## 100.0%

==> Downloading https://formulae.brew.sh/api/cask.jws.json

################################################################################################################################## 100.0%

Warning: python-tk@3.12 3.12.8 is already installed and up-to-date.

To reinstall 3.12.8, run:

  brew reinstall python-tk@3.12

What is the missing configuration that will connect the dots here?

0

Hi Byron

ModuleNotFoundError: No module named ‘_tkinter’

I am wondering if you get the same error outside of IDE using the same virtual environment? If so, then the issue is not related to PyCharm. 

Would it help to follow this guide with similar errors?

1

Many thanks to Mikhail Tarabrikov, this helped me immensely! As he suggests, this had nothing to do with PyCharm, it was how pyenv built python 3.12.1 originally.

While rebuilding python 3.12.1 to include tcl-tk, I encountered this build error under Mac OS 14.6.1

ginstall: cannot stat 'Modules/_curses.cpython-312-darwin.so': No such file or directory

but eventually I got past it with this workaround

 

0

请先登录再写评论。