This post is N high school student who will be the second article post. In this article, I couldn't import tkinter with python installed from pyenv, so I will write a workaround to enable it. It's almost a memorandum. .. .. As usual, I referred to various sites, so I would appreciate it if you could understand that.
macOS Mojave(10.14.6) python 3.7.0 pip 20.2.3 Homebrew 2.5.2
When I do import tkinter with python installed from pyenv, I get an import error. (I didn't expect to post an article so I didn't write down the code ...)
When I look it up Solve No module named ‘_tkinter’ on macOS (Mojave) (pyenv, Python3.x) I found an article with a content very similar to this symptom, so I tried to proceed with reference to this for the time being.
First of all, it seems that you have to uninstall python installed with pyenv
Preparing for a solution
#Back up what you installed with pip
$ pip freeze > pip.txt
#Uninstall
$ pyenv uninstall 3.7.0
#If from Homebrew tcl-Remove if tk is installed
$ brew uninstall tcl-tk
When you're ready so far, next Let's install 8.5 series from the site called ActiveTcl.
Once this is installed, install python again from pyenv. I have installed 3.7.0. At this time, copy the sentences written in the code here one by one and put them in the terminal. (I only put the install command at first, and I'm having a hard time)
$ CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \
$ LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
$ PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
$ pyenv install 3.7.0
$ pyenv global 3.7.0
Some people may mess with .bash_profile here. (I didn't have to mess with it)
Did this fix it? I thought, I tried it with REPL.
** No error! !! !! ** ** Now you can start developing! Thinking about it, hitting the next sentence ... This time I got a Runtime error ... what a hell ...
So this time I tried various things to solve this error. This github was referred to every site, so I read it once, but honestly I didn't understand it very well because I was a beginner. (If you understand, I think this can solve it)
So look for another site, Settings for using tkinter in pyenv environment of macOS Catalina 10.15.1 (python 3.7.x series) Written in Japanese Since the site came out, I proceeded with reference to this.
Preparing for a solution(Second time)
#Don't forget to back up your pip
$ pyenv uninstall 3.7.0
#from brew to tcl-Install tk
$ brew install tcl-tk
Then rewrite python-build. However, this file cannot be found even if it is opened in Finder, so enter the following command in the terminal.
open /usr/local
This will automatically open the Finder and display the file. I searched for python-build from here.
(In my environment) /Cellar/pyenv/plugins/python-build/bin/python-guild At, around line 770
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
In the column that says
$CONFIGURE_OPTS --with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
Replace with. After this, install python again.
$ pyenv install 3.7.0
Now, let's try again with the REPL.
** Healed this time! ** ** I didn't get an error this time, and I didn't get an error when I ran the file. This settled one case. It was quite difficult this time as well. I will write it if I have the opportunity to write an article.
Recommended Posts