A memorandum (masOS) that import tkinter could not be done with python installed from pyenv

Preface

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.

Operating environment

macOS Mojave(10.14.6) python 3.7.0 pip 20.2.3 Homebrew 2.5.2

The beginning of that

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.

Trial and error for a solution

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)

Solved for the time being ...?

Did this fix it? I thought, I tried it with REPL. スクリーンショット 2020-09-24 15.51.44.png

** No error! !! !! ** ** Now you can start developing! Thinking about it, hitting the next sentence ... This time I got a Runtime error ... what a hell ...

Trial and error for solution (second time)

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.

Location of python-build

(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

A memorandum (masOS) that import tkinter could not be done with python installed from pyenv
Tkinter could not be imported in Python
Make OpenCV3 available from python3 installed with pyenv
Import libraries that cannot be pip installed with PyCharm
Install the latest Python from pyenv installed with homebrew
A mechanism to call a Ruby method from Python that can be done in 200 lines
A memo that reads data from dashDB with Python & Spark
When I tried to use pip with python, I was told that XML_SetHashSalt could not be found.
[Python] Make a graph that can be moved around with Plotly
I couldn't use tkinter with python installed by pyenv of anyenv
Make a Spinbox that can be displayed in Binary with Tkinter
I made a shuffle that can be reset (reverted) with Python
Make a Spinbox that can be displayed in HEX with Tkinter
TensorFlow 2.2 can't be installed with Python 3.8!
A memo that allows you to change Pineapple's Python environment with pyenv
Extract lines that match the conditions from a text file with python
Measures that pip install cannot be done with pycharm or import ssl cannot be done
[Python] A program that creates stairs with #
Install Python as a Framework with pyenv
Use Anaconda-Python installed with pyenv from openFrameworks
A typed world that begins with Python
Build a python virtual environment with pyenv
Create a frame with transparent background with tkinter [Python]
[Python] A tool that allows intuitive relative import
[Python / Tkinter] A class that creates a scrollable Frame
A memorandum of calling Python from Common Lisp
Create a page that loads infinitely with python
[Python] I made a Youtube Downloader with Tkinter.
"Python Kit" that calls a Python script from Swift
How to use tkinter with python in pyenv
Read line by line from a file with Python
PIL cannot be installed by virtualenv with pyenv
Extract data from a web page with Python
Convert images from FlyCapture SDK to a form that can be used with openCV
When import tkinter is not possible on Mac OS X 10.11.3 (El Capitan) + pyenv + Python 3.5.1.
I want to tell people who want to import from a higher directory with Python direnv
Solved the problem that MacVim installed by Homebrew was not built by python of pyenv