# Problem with importing Python ROOT on windows

**URL:** <https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317>\
**Category:** ROOT\
**Tags:** bug, python, installation, root\
**Created:** [November 16, 2020, 9:24am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317 "2020-11-16T09:24:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![arteez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@arteez](https://root-forum.cern.ch/u/arteez)\
**Post date:** [November 16, 2020, 9:24am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/1 "2020-11-16T09:24:47Z")

</div>

Hello,

I am trying to use ROOT on windows. I ran into a problem with python. I cannot import ROOT python library - just a one liner

```python
import ROOT

```

shows an error

```auto
Traceback (most recent call last):
  File "C:\Programming\root\testTaskPy\main.py", line 1, in <module>
    import ROOT
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.

```

What I did

- Installed 32 bit python 3.9
- Added root to PYTHONPATH - specifically both the bin and the lib folders

I assume the problem is somewhere further down the chain as Python correctly tires to import from the root folder.

Any help would be appreciated, thank you!

As a side note I also have a problem with uproot related to this issue: [https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html](https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html)  
Though this is probably unrelated to this root forum? Or does anyone here use uproot for root as well?

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 16, 2020, 10:15am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/2 "2020-11-16T10:15:26Z")

</div>

I’ll check and let you know. In the meanwhile, can you try to call the `thisroot.bat` script (in the `bin` folder of ROOT) before starting python, to see if that solves the issue?

> [@arteez](#):
>
> As a side note I also have a problem with uproot related to this issue: [https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html](https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html)  
> Though this is probably unrelated to this root forum? Or does anyone here use uproot for root as well?

Well, I think this is unrelated

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 16, 2020, 11:59am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/3 "2020-11-16T11:59:11Z")

</div>

So ROOT v6.22.02 should work:

```auto
C:\Users\sftnight>build\v6-22-02\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
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>

```

---

<div class="post-metadata">

**Author:** ![arteez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@arteez](https://root-forum.cern.ch/u/arteez)\
**Post date:** [November 16, 2020, 8:49pm UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/4 "2020-11-16T20:49:42Z")

</div>

Hello, thanks for the reply, unfortunately it did not work - error message is still the same (attached below). I double checked the path. I use 32 bit version of python. `C:\Program Files (x86)\Python39-32` The 64 bit one was complaining that libPyRoot was not a valid win32 application or something along those lines. Can provide the full 64 bit error if necessary. Here is the output of the 32:

```auto
PS C:\> python --version
Python 3.9.0
PS C:\> .\root_v6.22.02\bin\thisroot.bat
PS C:\> python .\Programming\root\testTaskPy\main.py
Traceback (most recent call last):
  File "C:\Programming\root\testTaskPy\main.py", line 1, in <module>
    import ROOT
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.
PS C:\>

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 16, 2020, 10:06pm UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/5 "2020-11-16T22:06:24Z")

</div>

Can you try in a regular command prompt?

---

<div class="post-metadata">

**Author:** ![arteez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@arteez](https://root-forum.cern.ch/u/arteez)\
**Post date:** [November 17, 2020, 7:56am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/6 "2020-11-17T07:56:29Z")

</div>

Still the same thing even in cmd I’m afraid.

```auto
C:\>root_v6.22.02\bin\thisroot.bat

C:\>python --version
Python 3.9.0

C:\>python Programming\root\testTaskPy\main.py
Traceback (most recent call last):
  File "C:\Programming\root\testTaskPy\main.py", line 1, in <module>
    import ROOT
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.

C:\>

```

I’ve checked and in my bin folder there are multiple libPyRoot files - dll, pdp, pyd, rootmap, and a libPyRoot\_rdict.pcm

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 17, 2020, 8:02am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/7 "2020-11-17T08:02:16Z")

</div>

OK, then I don’t know, it should work… Can you try exactly what I did:

```auto
C:\Users\sftnight>build\v6-22-02\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
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>

```

The only difference is the Python version, that might be the issue…

---

<div class="post-metadata">

**Author:** ![arteez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@arteez](https://root-forum.cern.ch/u/arteez)\
**Post date:** [November 17, 2020, 8:07am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/8 "2020-11-17T08:07:17Z")

</div>

You’re probably right, I’ll download 3.8.3 32 bit and let you know

```auto
C:\>root_v6.22.02\bin\thisroot.bat

C:\>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:23:07) [MSC v.1927 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.
>>>

```

---

<div class="post-metadata">

**Author:** ![arteez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/c37758/32.png) [@arteez](https://root-forum.cern.ch/u/arteez)\
**Post date:** [November 17, 2020, 8:13am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/9 "2020-11-17T08:13:35Z")

</div>

Thank you so much!!! 3.8.3 fixed the problem!

```auto
C:\>root_v6.22.02\bin\thisroot.bat

C:\>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
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [November 17, 2020, 8:17am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/10 "2020-11-17T08:17:27Z")

</div>

Good! And note that a PowerShell script equivalent to `thisroot.bat` (`thisroot.ps1`) will be available in the next release of ROOT

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 1, 2020, 8:21am UTC](https://root-forum.cern.ch/t/problem-with-importing-python-root-on-windows/42317/11 "2020-12-01T08:21:23Z")

</div>

Closed on December 1, 2020, 8:21am UTC

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