# Python ROOT inside of Virtual Environment

**URL:** <https://root-forum.cern.ch/t/python-root-inside-of-virtual-environment/58554>\
**Category:** Newbie\
**Created:** [March 15, 2024, 7:35pm UTC](https://root-forum.cern.ch/t/python-root-inside-of-virtual-environment/58554 "2024-03-15T19:35:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheFibonacciEffect](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/thefibonaccieffect/32/35957_2.png) [@TheFibonacciEffect](https://root-forum.cern.ch/u/TheFibonacciEffect)\
**Post date:** [March 15, 2024, 7:35pm UTC](https://root-forum.cern.ch/t/python-root-inside-of-virtual-environment/58554/1 "2024-03-15T19:35:01Z")

</div>

I installed root using the Pacman package manager and pyroot seems to work fine in python when no virtual envorinment is activated:

```auto
➜ root git:(master) ✗ python3
Python 3.11.8 (main, Feb 12 2024, 14:50:05) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

```

However if I activate a virtial environment, python is not able to find it:

```auto
➜ root git:(master) ✗ source .venv/bin/activate
(.venv) ➜ root git:(master) ✗ which python3
/popos/home/caspar/Documents-old/code/root/.venv/bin/python3
(.venv) ➜ root git:(master) ✗ python3
Python 3.11.8 (main, Feb 12 2024, 14:50:05) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ROOT'
>>>

```

Does anyone know how to resolve this? I saw that using `thisroot.sh` seems to be discontinued.

* * *

_ROOT Version:_ 6.30.02-2  
_Platform:_ Arch Linux x86\_64 6.7.9-arch1-1  
_Compiler:_ Python 3.11.8-1

* * *

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 16, 2024, 5:32am UTC](https://root-forum.cern.ch/t/python-root-inside-of-virtual-environment/58554/2 "2024-03-16T05:32:38Z")

</div>

Hi,

Thanks for the interesting post and welcome to the ROOT community!

Why do you say `thisroot.sh` seems to be discontinued? In the mean time, I add in the loop @vpadulan and @jonas .

Best,  
D

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [March 16, 2024, 12:11pm UTC](https://root-forum.cern.ch/t/python-root-inside-of-virtual-environment/58554/3 "2024-03-16T12:11:09Z")

</div>

Hi @TheFibonacciEffect,

welcome to the ROOT forum!

It’s true that the Arch Linux ROOT package is set up in such a way that `thisroot.sh` is not needed anymore.

Concerning your problem: ROOT is installed in the system packages, and when you create a Python virtual environment all packages outside the virtual environment are ignored. This has nothing to do with ROOT, try the same with numpy 🙂

The solution is to create your virtual environment with the `--system-site-packages` flag to specify that you want to also use system packages.

See also this discussion on stackoverflow:

> <https://stackoverflow.com/questions/14571454/virtualenv-specifing-which-packages-to-use-system-wide-vs-local>
