Importing python modules into iron python

Good morning!

Quick question. I’m trying to use the method time.sleep() from pythons time module. Here is my code that is not working:

image

Can someone please help correct this import so I can use this method?

Thank you in advance!

You do not need to import sys to use the time module. You can simply import time. For example:

import time
time_before = time.time()
time.sleep(10)
time_after = time.time()
OUT = time_before, time_after
1 Like

Just realized this. Thank you for the help!

I’ve had a similar issue before trying to import random. One thing I noticed in your code is that you’re importing from Python 3, but I think Dynamo uses IronPython 2.7. I’m not sure if this makes a difference, but it might be something to pay attention to.

I found my solution in a post like this one:
Cant import random module to Python

That post includes the code used to path to the IronPython modules.

2 Likes

Glad you brought this up, may help another user. I also discovered this when trying to use another module, so I changed my pyth_path to my Python 2 Lib path.

I believe it should more specifically be the IronPython 2.7 Lib path e.g.:
r'C:\Program Files (x86)\IronPython 2.7\Lib'
or
r'C:\Program Files\IronPython 2.7\Lib'