# Cant import random module to Python

**URL:** <https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617>\
**Category:** Developers\
**Created:** [August 15, 2016, 11:08am UTC](https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617 "2016-08-15T11:08:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [August 15, 2016, 11:08am UTC](https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617/1 "2016-08-15T11:08:11Z")

</div>

I’m trying to import the random module into python and the node throws and exception. Any ideas?

I’ve tried

`import random`

and

```auto
    import sys
    pyt_path = r'C:\Program Files (x86)\\IronPython 2.7\Lib'
    sys.path.append(pyt_path)

```

to no avail. The IronPython console has no issue with `import random` and works as expected

![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/d/dae3267ac10939de72b127de70a7116ff2186bac.jpg)

---

<div class="post-metadata">

**Author:** ![Konrad\_K\_Sobon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/konrad_k_sobon/32/8838_2.png) [@Konrad\_K\_Sobon](https://forum.dynamobim.com/u/Konrad_K_Sobon)\
**Post date:** [August 15, 2016, 12:33pm UTC](https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617/2 "2016-08-15T12:33:40Z")

</div>

You would first have to define a path to IronPython’s librar, append it to the system path and then finally import the module.

```auto
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import random

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

#Assign your output to the OUT variable.
OUT = random.random()

```

Works as expected:

![](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/d/d7cb05ca369c09aee9c398fde5bdfb75986eb274.jpg)

---

<div class="post-metadata">

**Author:** ![Einar\_Raknes](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/einar_raknes/32/8566_2.png) [@Einar\_Raknes](https://forum.dynamobim.com/u/Einar_Raknes)\
**Post date:** [August 15, 2016, 12:35pm UTC](https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617/3 "2016-08-15T12:35:26Z")

</div>

This works for me: (Edit: to late)

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/d/da959853397cc387abf09bfccd8f7ff718e9b6f0.png)

```
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import random
OUT = random.randint(0,9)
```

---

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [August 15, 2016, 12:53pm UTC](https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617/4 "2016-08-15T12:53:17Z")

</div>

Thanks guys. Thought it was going to be something simple I was overlooking!

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [August 15, 2016, 12:55pm UTC](https://forum.dynamobim.com/t/cant-import-random-module-to-python/5617/5 "2016-08-15T12:55:38Z")

</div>

This works for me too:  
 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/9/99c5d14b045da10aebf05fb07d1ef42f7185cc0f.png)
