# \[Windows 10\] ROOT 6.28 with Miniconda Python 3.10 slow import

**URL:** <https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763>\
**Category:** ROOT\
**Tags:** python, tmva, root\
**Created:** [February 24, 2023, 2:33pm UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763 "2023-02-24T14:33:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [February 24, 2023, 2:33pm UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/1 "2023-02-24T14:33:42Z")

</div>

Continuing the discussion from [[Windows 10] ROOT 6.28 build with Miniconda Python 3.10 crashed](https://root-forum.cern.ch/t/windows-10-root-6-28-build-with-miniconda-python-3-10-crashed/53554):

* * *

_ROOT Version:_ ROOT 6.28/00 (64 bits)  
_Python:_ [Miniconda3-py310\_23.1.0-1-Windows-x86\_64.exe](https://repo.anaconda.com/miniconda/Miniconda3-py310_23.1.0-1-Windows-x86_64.exe)  
_Platform:_ Windows 10 (20H2)  
_Compiler:_ Visual Studio 2022 (17.3.6)

* * *

Dear ROOT developers and maintainers,

I built ROOT 6.28 with Miniconda Python 3.10 on Windows 10 like in the mentioned topic. And here are the selected features:

```plaintext
-- Enabled support for: asimage builtin_afterimage builtin_clang builtin_cling builtin_freetype builtin_llvm builtin_lz4 builtin_nlohmannjson builtin_pcre builtin_xxhash builtin_zstd dataframe fftw3 mlp minuit2 pyroot shared xml

```

However ROOT module loading time in Python seems particularly long:

```plaintext
(base) PS C:\URANIE\33846> Measure-Command {python -c "import ROOT"}

Days : 0
Hours : 0
Minutes : 0
Seconds : 4
Milliseconds : 435
Ticks : 44352536
TotalDays : 5,13339537037037E-05
TotalHours : 0,00123201488888889
TotalMinutes : 0,0739208933333333
TotalSeconds : 4,4352536
TotalMilliseconds : 4435,2536

(base) PS C:\URANIE\33846>

```

A verbose loading seems to indicate a bottleneck at TMVA pythonization:

```plaintext
(base) PS C:\URANIE\33846> Measure-Command {python -vc "import ROOT"}
[...]
import 'ROOT._pythonization._tmva._crossvalidation' # <_frozen_importlib_external.SourceFileLoader object at 0x000002CFE61C8BB0>
# C:\URANIE\33846\uranie_master_win10_saclay\uranie\bin\ROOT\_pythonization\_tmva\ __pycache__ \_rbdt.cpython-310.pyc matches C:\URANIE\33846\uranie_master_win10_saclay\uranie\bin\ROOT\_pythonization\_tmva\_rbdt.py
# code object from 'C:\\URANIE\\33846\\uranie_master_win10_saclay\\uranie\\bin\\ROOT\\_pythonization\\_tmva\\ __pycache__ \\_rbdt.cpython-310.pyc'
import 'ROOT._pythonization._tmva._rbdt' # <_frozen_importlib_external.SourceFileLoader object at 0x000002CFE61C8CD0> # [Ctrl + C]
(base) PS C:\URANIE\33846> echo $?
False
(base) PS C:\URANIE\33846>

```

Removing the directory seems to solve loading issue:

```plaintext
(base) PS C:\URANIE\33846> mi C:\URANIE\33846\cache\outputs\root\bin\ROOT\_pythonization\_tmva .                        
(base) PS C:\URANIE\33846> Measure-Command {python -c "import ROOT"}

Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 650
Ticks : 6508886
TotalDays : 7,53343287037037E-06
TotalHours : 0,000180802388888889
TotalMinutes : 0,0108481433333333
TotalSeconds : 0,6508886
TotalMilliseconds : 650,8886

(base) PS C:\URANIE\33846> python -c "import ROOT"
(base) PS C:\URANIE\33846> $?
True
(base) PS C:\URANIE\33846>

```

Do you know how to explain this loading time issue?

Could you selectively define `py2_py3_sources` in [root/CMakeLists.txt at v6-28-00 · root-project/root · GitHub](https://github.com/root-project/root/blob/v6-28-00/bindings/pyroot/pythonizations/CMakeLists.txt#L31)?

In case it might be useful here is a temporary link to my ROOT installation with Miniconda: [FileSender](https://filesender.renater.fr/?s=download&token=d6617eb3-0b3c-4c34-83a4-3416949862ed).

---

<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:** [February 27, 2023, 9:55am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/2 "2023-02-27T09:55:09Z")

</div>

> [@Salomon](#):
>
> Do you know how to explain this loading time issue?

I think we’ll have to investigate

> [@Salomon](#):
>
> Could you selectively define `py2_py3_sources` in [root/CMakeLists.txt at v6-28-00 · root-project/root · GitHub](https://github.com/root-project/root/blob/v6-28-00/bindings/pyroot/pythonizations/CMakeLists.txt#L31)?

Why would you need to customize this?

---

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [February 27, 2023, 10:08am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/3 "2023-02-27T10:08:05Z")

</div>

Thank you for your answer.

Concerning the customisation of `py2_py3_sources`, here is the patch I used as a workaround for my special case (without TMVA): [root\_v6-28-00\_tmva.patch.txt](https://root-forum.cern.ch/uploads/short-url/kdVJap6W5SSk91BMjr2vTUCLY1S.txt) (1.4 KB)

The loading time issue seems to be solved then:

```plaintext
(base) PS C:\URANIE\33846\root_v6-28-00_b0f07d5c_py310_e3b0c442-3> gci .\outputs\root\bin\ROOT\_pythonization\_tmva
gci : Impossible de trouver le chemin d'accès «
C:\URANIE\33846\root_v6-28-00_b0f07d5c_py310_e3b0c442-3\outputs\root\bin\ROOT\_pythonization\_tmva», car il n'existe
pas.
Au caractère Ligne:1 : 1
+ gci .\outputs\root\bin\ROOT\_pythonization\_tmva
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (C:\URANIE\33846...onization\_tmva:String) [Get-ChildItem], ItemNotFound
   Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

```

```plaintext
(base) PS C:\URANIE\33846\root_v6-28-00_b0f07d5c_py310_e3b0c442-3> . .\outputs\root\bin\thisroot.ps1
(base) PS C:\URANIE\33846\root_v6-28-00_b0f07d5c_py310_e3b0c442-3> Measure-Command {python -c "import ROOT"}

Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 654
Ticks : 6548666
TotalDays : 7,57947453703704E-06
TotalHours : 0,000181907388888889
TotalMinutes : 0,0109144433333333
TotalSeconds : 0,6548666
TotalMilliseconds : 654,8666

(base) PS C:\URANIE\33846\root_v6-28-00_b0f07d5c_py310_e3b0c442-3>

```

I suppose enabling `tmva-pymva` option might cause the loading time issue again.

---

<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:** [February 27, 2023, 10:10am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/4 "2023-02-27T10:10:49Z")

</div>

OK, so that would be interesting to see if the issue exists on other platforms. Maybe @moneta or @vpadulan could be interested to give it a try?

---

<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:** [February 27, 2023, 10:23am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/5 "2023-02-27T10:23:43Z")

</div>

And BTW, I think what you propose for modularizing the `bindings/pyroot/pythonizations/CMakeLists.txt` make sense. I’ll check with @vpadulan and @Axel what we can do there.

---

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [February 27, 2023, 10:27am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/6 "2023-02-27T10:27:01Z")

</div>

Thank you for your messages.

I took inspiration from `dataframe` section: [root/CMakeLists.txt at v6-28-00 · root-project/root · GitHub](https://github.com/root-project/root/blob/v6-28-00/bindings/pyroot/pythonizations/CMakeLists.txt#L11).

---

<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:** [February 27, 2023, 11:27am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/7 "2023-02-27T11:27:43Z")

</div>

Yes, I’ve seen that. I think we should do the same for TMVA (PyMVA) and roofit

---

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [February 27, 2023, 11:28am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/8 "2023-02-27T11:28:54Z")

</div>

Sorry. I didn’t pay attention to [[PyROOT] Only build RooFit and TMVA pythonizations if needed · root-project/root@d759a42 · GitHub](https://github.com/root-project/root/commit/d759a42a33fe6a9195c3c79275fe05e4da2b4195).

---

<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:** [February 27, 2023, 11:31am UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/9 "2023-02-27T11:31:19Z")

</div>

Oh you’re right! I guess we can backport this to `v6-28-00-patches`…

---

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [March 1, 2023, 1:23pm UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/10 "2023-03-01T13:23:51Z")

</div>

Hello,

In a derived project of ROOT, I investigated a class which is similar to [MsgLogger](https://github.com/root-project/root/blob/v6-28-00/tmva/tmva/inc/TMVA/MsgLogger.h).

And the root cause of Python loading time issue might be related to `std::ostringstream` inheritance:

- Derived project:

```bash
14:17 $ git grep "public std::ostringstream"
dataSERVER/souRCE/UMessageLogger.h:class UMessageLogger: public std::ostringstream, public TObject
✔ /[...]/33846/souRCE [master|…5]

```

- ROOT, see [root/MsgLogger.h at v6-28-00 · root-project/root · GitHub](https://github.com/root-project/root/blob/v6-28-00/tmva/tmva/inc/TMVA/MsgLogger.h#L57:)

```bash
14:17 $ git grep "public std::ostringstream"
core/foundation/inc/ROOT/RLogger.hxx:class RLogBuilder : public std::ostringstream {
tmva/tmva/inc/TMVA/MsgLogger.h: class MsgLogger : public std::ostringstream, public TObject {
✔ /[...]/33846/root [v6-28-00|⚑ 1]

```

Further investigation may support or reject this hypothesis.

---

<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:** [March 1, 2023, 1:25pm UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/11 "2023-03-01T13:25:44Z")

</div>

Thanks for the investigations! Maybe @moneta would be interested

---

<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:** [March 15, 2023, 1:26pm UTC](https://root-forum.cern.ch/t/windows-10-root-6-28-with-miniconda-python-3-10-slow-import/53763/12 "2023-03-15T13:26:07Z")

</div>

Closed on March 15, 2023, 1:26pm UTC

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