ROOT Version: 6.26/02 Platform: Windows 10 Python version: 3.8.10 (changed to this for compatibility with ROOT python version below) ROOT python version: 3.8.10
Problem:import ROOT in cmd and VSCode
Hello!
The command “import ROOT” provides two problems in my system.
Opening python in cmd, running “set PYTHONPATH=C:…\root\bin” and using command “import ROOT” results in ImportError: Failed to import libcppyy3_8. Please check that ROOT has been built for Python 3.8 (this is the last line of the error message).
Running a file with “import ROOT” in VSCode, in a Jupyter Notebook results in ModuleNotFoundError: No module named ROOT.
I would like to fix these problems. Could you point me to something?
Best regards,
ovs
EDIT:
ROOT and python both have 32-bit architecture, and the usual “thisroot.bat” -script has been used.
Welcome to the ROOT Forum!
Please make sure you have the same architecture (32 bit vs 64 bit) for both Python and ROOT and use the root\bin\thisroot.bat script
Then it should work, at least from the command prompt. And BTW,
Please don’t do this. This is not needed if you called thisroot.bat before starting Python.
One more thing: Can you paste the output of root-config --python-version?
Here is the copy-pasted code from cmd. I actually need to use the command root -config --python-version, with one space after “root”, otherwise the command is not recognized.
C:\root\bin>thisroot.bat
C:\root\bin>root -config --python-version
ROOT ./configure options:
CMAKE_CXX_STANDARD_LIBRARIES=kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib CMAKE_C_STANDARD_LIBRARIES=kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib FFTW_INCLUDE_DIR=C:/libs/fftw/3.3.5 FFTW_LIBRARY=C:/libs/fftw/3.3.5/fftw3-3.lib GLEW_INCLUDE_DIR=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/glew/inc GLEW_INCLUDE_DIRS=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/glew/inc GLEW_LIBRARIES=GLEW::GLEW GLEW_LIBRARY=$<TARGET_FILE:GLEW> LZ4_INCLUDE_DIR=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/lz4 LZ4_INCLUDE_DIRS=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/lz4 LZ4_LIBRARIES=LZ4::LZ4 LZ4_LIBRARY=$<TARGET_FILE:lz4> LZ4_VERSION=1.9.3 LZ4_VERSION_STRING=1.9.3 NUMPY_INCLUDE_DIRS=C:/Python38/Lib/site-packages/numpy/core/include OPENGL_gl_LIBRARY=opengl32 OPENGL_glu_LIBRARY=glu32 PCRE_INCLUDE_DIR=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/build/builtins/pcre/PCRE-prefix/src/PCRE-build PCRE_LIBRARIES=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/build/builtins/pcre/PCRE-prefix/src/PCRE-build/Release/pcre.lib PCRE_PCRE_LIBRARY=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/build/builtins/pcre/PCRE-prefix/src/PCRE-build/Release/pcre.lib PCRE_VERSION=8.43 PYTHON_INCLUDE_DIRS=C:/Python38/include PYTHON_LIBRARIES=C:/Python38/libs/python38.lib PYTHON_LIBRARY_DIR=C:/Python38/libs PYTHON_VERSION_MAJOR=3 PYTHON_VERSION_MINOR=8 PYTHON_VERSION_STRING=3.8.10 ZLIB_INCLUDE_DIR=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/zlib ZLIB_INCLUDE_DIRS=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/zlib ZLIB_LIBRARIES=ZLIB::ZLIB ZLIB_LIBRARY=$<TARGET_FILE:ZLIB> ZLIB_VERSION=1.2.8 ZLIB_VERSION_STRING=1.2.8 ZSTD_INCLUDE_DIR=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/zstd ZSTD_INCLUDE_DIRS=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/zstd ZSTD_LIBRARIES=ZSTD::ZSTD ZSTD_LIBRARY=$<TARGET_FILE:ZSTD> ZSTD_VERSION=1.4.8 ZSTD_VERSION_STRING=1.4.8 xxHash_INCLUDE_DIR=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/xxhash xxHash_INCLUDE_DIRS=C:/build/ws/BUILDTYPE/Release/LABEL/windows64/V/6-26/root/builtins/xxhash xxHash_LIBRARIES=xxHash::xxHash xxHash_LIBRARY=$<TARGET_FILE:xxhash> xxHash_VERSION=0.8.0 xxHash_VERSION_STRING=0.8.0
C:\root\bin>python
Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:34:34) [MSC v.1928 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
File "C:\root\bin\cppyy\__init__.py", line 60, in <module>
importlib.import_module(libcppyy_mod_name)
File "C:\Users\onnis\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
File "<frozen importlib._bootstrap>", line 556, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1166, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed while importing libcppyy3_8: %1 ei ole kelvollinen Win32-sovellus.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\root\bin\ROOT\__init__.py", line 22, in <module>
import cppyy
File "C:\root\bin\cppyy\__init__.py", line 62, in <module>
raise ImportError(
ImportError: Failed to import libcppyy3_8. Please check that ROOT has been built for Python 3.8
>>>
So I only manage to reproduce the issue when using a newest version of Python (e.g. 3.9.6). I tried ROOT v6.26.02 with Python 3.8.3 and it works just fine:
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.15
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
C:\Users\sftnight>Downloads\root\bin\thisroot.bat
C:\Users\sftnight>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> quit()
C:\Users\sftnight>
Forget about root -config --python-version, this is useless, the root-config.bat script is missing (I’ll fix this). And you downloaded root_v6.26.02.win32.vc16.zip, right?
You told me you installed ROOT 32 bit (see the first question I asked). root_v6.26.02.win64.vc17 is 64 bit (see the win64 in the name?), so I think we found the issue…
It would seem that now the cmd-side is OK. The VSCode still has the same problem, but I’ll try to sort it out in due time. A huge thanks for the patience and help!
I created a .ipynb file in VSCode, and ran the code I mentioned.
Running root --notebook in the VSCode terminal (and other terminals) gives an error
Jupyter command `jupyter-notebook` not found.
I have installed jupyter and metakernel, so the problem could be in the terminal not finding the jupyter installation.
As a side question, if I want to use a .ipynb file “locally” in VSCode, is the root --notebook command required? I must admit my understanding about the jupyter ecosystem is not too extensive.
Sorry, but the only way I know is to use Jupyter notebook via root --notebook on the command prompt. I have no experience with the way you are trying to use it in VS Code.