Python ImportError: no module named os

On another users PC in my company, they are receiving the import error shown in the picture and in title of having no os module.

As (I believe?) the os module is .net standard and is not ironpython specific it shouldn’t matter that the sys library isn’t being imported.

Everything I can see on stack overflow seems to point towards needing a re-install of Python but how is that possible inside the inbuilt Iron Python version environment of Dynamo?

Any help appreciated.

Hmm… Yes an odd one… It should work…

I presume you checked that it exists here?

image

Cheers,

Mark

1 Like

Depending on your dynamo version, it may automatically load the modules in but if you are using say Dynamo 2.0.4 then you will need to add the following:
image

Note: I cannot remember the version of dynamo that the auto load of modules from this folder was implemented.

Code for ease of copy/paste:

#Created By Brendan Cassidy

import clr

#Sets up new path to ironpython module Library
#See https://docs.python.org/2/library/sys.html
import sys
sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")

OUT=[]

#Imports operating system interfaces
#See https://docs.python.org/2/library/os.html
import os
3 Likes

I hadn’t checked that location but as it happens they do have that file even though it still doesn’t work

The plot thickens…

1 Like

@haganjake2 ,


hmmmmm… :confused:

Ok for some reason it seems to work when importing clr and sys first.

We’re using Dynamo version 2.6.1 which I believe should be above the autoloading.

It was working fine for me without the need to import the others so not a clue what was going on. It works for us both afterwards so will make the change.

Would be good to understand why this is the case though?

1 Like

My belief: without SYS first being imported the Python environment can’t access the standard system configurations, as where OS lives is unknown as the paths are moot; sys and clr both are forced into the IronPython environment reguardless of installation path, but they are somewhat unique in that respect.

2 Likes

Interesting and seems to make sense.

The anomaly with this though is that importing OS for many other users (myself included), using the same script with the same code was not generating an error!

Not a biggie just one of those weird ones that it’s always fun to try and get to the bottom of haha.

Thanks for the input anyways

I believe os can work without sys being imported in Dynamo Python, but it needs clr.

1 Like

Within the IronPython Lib folder there is a “OS” Module.

Located here for revit 2019 and before: C:\Program Files (x86)\IronPython 2.7\Lib
For Revit 2020: C:\Program Files\Autodesk\Revit 2020\AddIns\DynamoForRevit\IronPython.StdLib.2.7.8

Though i think revit 2020 version of dynamo and above may automatically load in the folder path.