Flair installation on macOS Catalina error

Dear FLUKA experts,
I’m installing flair on a new Mac. I followed every step in https://flair.web.cern.ch/flair/download.html. However, when I type in flair in Terminal, it gave error message:

Traceback (most recent call last):
File “/Users/z/FLUKA/flair-3.0/flair.py”, line 70, in
import tkinter as tk
File “/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/tkinter/init.py”, line 36, in
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named ‘_tkinter’

And here is the python packages I installed using macport:

sudo port install python37
sudo port select --set python3 python37
sudo port install py37-tkinter
sudo port install py37-Pillow
sudo port install py37-numpy
sudo port install py37-matplotlib +tkinter
sudo port install py37-scipy
sudo port install py37-pydicom

Any advice?

Thank you!
Z.

Dear @Ephemera,
Could you possibly provide the output of this command?
port echo requested
Thanks, luigi

Dear Luigi,
Yes, of course. Here is the output of the command:
gcc9 @9.3.0_1
gdb @9.1_0
ghostscript @9.50_1+x11
gnuplot @5.2.8_0+aquaterm+luaterm+pangocairo+wxwidgets+x11
pkgconfig @0.29.2_0
py37-matplotlib @3.2.1_0+tkinter+webagg
py37-numpy @1.18.5_0+gfortran+openblas
py37-Pillow @7.1.2_0
py37-pydicom @1.4.2_0
py37-scipy @1.4.1_0+gfortran+openblas
py37-tkinter @3.7.7_0
py38-matplotlib @3.2.1_0+tkinter+webagg
py38-numpy @1.18.5_0+gfortran+openblas
py38-Pillow @7.1.2_0
py38-pydicom @1.4.2_0
py38-scipy @1.4.1_0+gfortran+openblas
py38-tkinter @3.8.3_0
python37 @3.7.7_0
python38 @3.8.3_0
xorg @20090316_0
xorg-server @1.20.8_0

Thanks!
Z.

Thanks!
Z.

Thanks @Ephemera,
The setup seems fine, except that you have both py3.7 and py3.8.
Unless you need for specific reasons, I have experience that the two versions can create problem.
Can you also provide the output of this command?
port select --summary
Thanks, luigi

Dear Luigi,
I cleaned up the py3.8. now the output of the port echo requested becomes:
gcc9 @9.3.0_1
gdb @9.1_0
ghostscript @9.50_1+x11
gnuplot @5.2.8_0+aquaterm+luaterm+pangocairo+wxwidgets+x11
pkgconfig @0.29.2_0
py37-matplotlib @3.2.1_0+tkinter+webagg
py37-numpy @1.18.5_0+gfortran+openblas
py37-Pillow @7.1.2_0
py37-pydicom @1.4.2_0
py37-scipy @1.4.1_0+gfortran+openblas
py37-tkinter @3.7.7_0
python37 @3.7.7_0
xorg @20090316_0
xorg-server @1.20.8_0

The output of port select --summary is:

Thank you!
Z.

Hi @Ephemera,
I guess that you still get the same error.
We have the same Macports setup, so I don’t think there is any problem there.
What I do not understand is why is the called the python from XCode and not the one from Macports.
So there is something wrong in the environment configuration.

Could you possibly check the output of these two commands?
which -a python3
and
env | grep PATH
Could you also possibly make a test in a new Terminal?
Cheers, luigi

Dear Luigi ,
Yes. I got the same error.
The output of which -a python3 is:
/usr/bin/python3
/opt/local/bin/python3
and the output of env | grep PATH is:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin

Thank you!
Z.

Hi @Ephemera,
I see that your PATH is correctly set, but the output of the which command shows the python3 instances in the reversed order.
Could you possibly make the test in a new Terminal?
I bet that the output of the which -a python3 will show the two lines inverted and then Flair should work.
Cheers luigi

Dear Luigi,
I opened up a new Terminal, and type in which -a python3, and the output is still in the same order as my last post.
/usr/bin/python3
/opt/local/bin/python3
and typing in flair still gave the same error message…
I even restarted my Mac, and same thing happened.
Is there a way to manually invert their order?

Thank you!
Z.

Hi @Ephemera,
in a previous post, you showed that the PATH variable was correctly set.
So the first instance of python3 should be /opt/local/bin/python3 but apparently it’s not the case…

Please check if the ~/.bash_profile contains the following line
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
which MacPorts should have added.

As a last recourse, you can explicitly set the PYTHON variable before launching Flair:
PYTHON=/opt/local/bin/python3 <FLAIR_INSTALLATION_DIR>/flair
where <FLAIR_INSTALLATION_DIR> should be /Users/z/FLUKA/flair-3.0/ in your case

Dear Luigi,
Thank you very much!

This was the problem, MacPorts did not add export PATH=/opt/local/bin:/opt/local/sbin:$PATH to my profile (in my case is ~/.zshrc.
Thank you so much for your help!!
Z.