问题描述
我尝试在Google colajuatory Jupiter笔记本上安装CERN ROOT http://root.cern.ch https://colab.research.google.com .我无法让python与ROOT一起运行,它在以下位置崩溃:导入根
I have tried to install CERN ROOT http://root.cern.ch on google colaboratory Jupiter notebook https://colab.research.google.com. I can't get python running with ROOT, it crashes at:import ROOT
我一直照常安装ROOT:
I have been installing ROOT as usual:
!mkdir -p APPS
!pwd
!cd APPS && wget https://root.cern/download/root_v6.16.00.Linux-ubuntu18-x86_64-gcc7.3.tar.gz
!cd APPS && tar -xf root_v6.16.00.Linux-ubuntu18-x86_64-gcc7.3.tar.gz
!ls APPS/root/bin/thisroot.sh
!source APPS/root/bin/thisroot.sh
!echo $ROOTSYS
!echo $PYTHONPATH
import ROOT
脚本APPS/root/bin/thisroot.sh应该定义PYTHONPATH和ROOTSYS变量,因此应该允许从python使用ROOT.
The script APPS/root/bin/thisroot.sh should define PYTHONPATH and ROOTSYS variables, so this should allow to use ROOT from python.
问题:运行此脚本后,未设置环境变量,因此无法使用python运行ROOT.
PROBLEM:After running this script the environmental variables are not set, so I can't run ROOT with my python.
那么,如何设置这些变量??
So, how to setup these variables????
谢谢,马辛
推荐答案
我也尝试在Google colajuatory Jupiter笔记本上使用ROOT,我发现在导入ROOT之前应先加载一些库.以下代码至少在我的笔记本中有效.
also I have tried to use ROOT on the google colaboratory Jupiter notebook, and I found that some libraries should be loaded before importing ROOT. The following code works at least in my notebook.
!mkdir -p APPS
!pwd
!cd APPS && wget https://root.cern.ch/download/root_v6.13.08.Linux-ubuntu18-x86_64-gcc7.3.tar.gz
!cd APPS && tar -xf root_v6.13.08.Linux-ubuntu18-x86_64-gcc7.3.tar.gz
import sys
sys.path.append("/content/APPS/root/lib")
import ctypes
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libCore.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libThread.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libImt.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libRIO.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libNet.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libTree.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libMathCore.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libMatrix.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libHist.so')
ctypes.cdll.LoadLibrary('/content/APPS/root/lib/libGraf.so')
import ROOT
h = ROOT.TH1F("gauss","Example histogram",100,-4,4)
h.FillRandom("gaus")
c = ROOT.TCanvas("myCanvasName","The Canvas Title",800,600)
h.Draw()
c.Draw()
如果使用ROOT v6.16.00,则会看到如下错误.
If you use the ROOT v6.16.00, you would see an error as below.
OSError: /content/APPS/root/lib/libImt.so: undefined symbol: _ZN3tbb10interface78internal20isolate_within_arenaERNS1_13delegate_baseEl
顺便说一下,下面列出了google colaboratory的Ubuntu,gcc和python版本.
By the way, the versions of Ubuntu, gcc, and python of the google colaboratory are listed below.
Ubuntu 18.04.2 LTS (Bionic Beaver)
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
这篇关于在Google Jupyter Notebook上安装CERN ROOT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!