Root installed through macports, cannot be imported in python

I just downloaded Root v 6.24.06 through macports. What are the neccessary steps I need to take in order to be able to “import ROOT” in python? I’m currently using pycharm. I’m entirely new to root and command line code, so please bare with me!

Try to use vscode or directly import ROOT in command mode?

As for me, I use ROOT on Ubuntu, and I found that path setting by running /bin/thisroot.sh made no sense to PyCharm, I had to edit the startup script of PyCharm manually while vscode worked well.Maybe it was because there is something different between command in PyCharm and that in system.

1 Like

Hi @cyydot ,
and welcome to the ROOT forum. Let’s see if @jonesc has further suggestions :smiley:

Cheers,
Enrico

MacPorts’ build of ROOT has full support for python. What you have to bear in mind though is it is built against one macports python ports, and not the system python. i.e. I currently have installed

Oberon ~/Projects/MacPorts/ports > port installed root6 
The following ports are currently installed:
  root6 @6.24.06_2+cocoa+davix+gcc11+graphviz+gsl+opengl+python310+roofit+tmva+xml+xrootd (active)

from the above you can see I am using python 3.10.

To use it then, you have to start the correct python version. There are a number of ways you can do this.

  1. directly with the macports command, e.g.
Oberon ~/Projects/MacPorts/ports > python3.10
Python 3.10.2 (main, Jan 15 2022, 11:31:35) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> 
  1. if you do not want to have to start python with the specific versioned command, you can choose to make a given macports python your default, using port select
 Oberon ~/Projects/MacPorts/ports > port select python
Available versions for python:
	none (active)
	python310
	python39

so then, if I was to run

Oberon ~/Projects/MacPorts/ports > sudo port select python python310
Selecting 'python310' for 'python' succeeded. 'python310' is now active.

macports python 3.10 is now the default for python

Oberon ~/Projects/MacPorts/ports > which python
/opt/local/bin/python
Oberon ~/Projects/MacPorts/ports > ls -l /opt/local/bin/python
lrwxr-xr-x  1 root  admin  25 26 Jan 12:01 /opt/local/bin/python -> /opt/local/bin/python3.10

if you prefer, the same can be done for the python3 command

Oberon ~/Projects/MacPorts/ports > sudo port select python3 python310
Selecting 'python310' for 'python3' succeeded. 'python310' is now active.
Oberon ~/Projects/MacPorts/ports > which python3
/opt/local/bin/python3
Oberon ~/Projects/MacPorts/ports > ls -l /opt/local/bin/python3
lrwxr-xr-x  1 root  admin  25 26 Jan 12:03 /opt/local/bin/python3 -> /opt/local/bin/python3.10
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.