Windows 10 cmd/VSCode: "Failed to import libcppyy3_8" and "No module named 'ROOT"


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.

  1. 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).
  2. 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

Hello and thanks for the warm welcome!

Good that you mentioned, I should add that I have done both of the procedures you mentioned.

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?

Thanks for the help. However, even after this the cmd does not work, and inputs the same error.

The output of root-config --python-version is given below.

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

I don’t think so. Open a command prompt, call thisroot.bat and type root-config --python-version. It should give something like this:

C:\Users\bellenot>root-config --python-version
 3.9.6

C:\Users\bellenot>

Here is what I do:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.15
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Users\bellenot>build\x86\release\bin\thisroot.bat

C:\Users\bellenot>root-config --python-version
 3.9.6

C:\Users\bellenot>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:04:37) [MSC v.1929 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

Can you show me (copy and paste) the same procedure?

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
>>>

OK, That’s weird. I’ll try to reproduce the problem and come back to you

1 Like

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>

Hello!

Python 3.8.3 produces the same error, and root -config --python-version still outputs the same long message, so no progress here.

Thanks for your help, still!

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?

1 Like

I actually downloaded the root_v6.26.02.win64.vc17. I’ll try the one you mentioned.

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… :wink:

Hello!

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! :slightly_smiling_face:

1 Like

Say, would you know anything about the Jupyter Notebook? The following snippet at least starts to execute, however it kills the kernel:

import sys
sys.path.append("C:/root/bin/")
import ROOT

The errors given in the output are (essentially):

C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:205:12: error: redefinition of '_CrtEnableIf<true, _Ty>'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:596:16: error: redefinition of '__crt_locale_data_public'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:603:16: error: redefinition of '__crt_locale_pointers'
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:611:16: error: redefinition of '_Mbstatet'

Canceled future for execute_request message before replies were done

Can you fully describe what you did? How do you start your notebook? Did you try root --notebook?

Hello!

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.

Where do you edit your code? My idea is to use VSCode to open a file, and write code to it.