Import Python Module

Hello pyRevit Friends :slight_smile:

I want to import a pyrevit module.

I installed Python for Windows and the following modules:

But “import pywin32” just gives me this error:

IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\....\", line 1, in <module>
ImportError: No module named pywin32

What am I doing wrong ?

I installed this Python version:

Hey, to start things out, could you give some more info, for example ;

  • What directory do you have when you enter “pip -V” in the console? This should be the same entered in PYTHONPATH in the system variables (explained below)
  • When executing your code in python, what version of python it’s using? code :

import sys

I’m seeing “IronPython” on the Traceback, it’s only possible using external modules with cpython in pyRevit, and if I’m not wrong, you should have the same version of python, using the latest one available for cpython would be 3.8.5. There’s some discussion in this forum and Autodesk Forum. There is a video by Ehsan Iran-Nejad here

And I encountered some problems concerning ADMIN authorization on my company’s PC, I tried using on my personal PC and it did the trick.

Best of luck!

1 Like

Hello @ValquirPacheco,

Thanks for this detailed informations!

Ok, so Python Modules will only run with Cpython, so i would have to change my scripts to Cpython if i want to use these modules, that doesn´t make me very happy…

Following your instructions, I downloaded the right python version, installed some modules and created a PYTHONPATH in the system properties with the right path. I still can´t get it to work.

#! python3
import pywinauto
CPython Traceback:
ModuleNotFoundError : No module named 'win32api'
 File "C:\Users\...\", line 2, in <module>
import pywinauto
 File "c:\users\...\appdata\local\programs\python\python38\lib\site-packages\pywinauto\", line 59, in <module>
 import win32api # noqa: E402

bei Python.Runtime.Runtime.CheckExceptionOccurred()
 bei Python.Runtime.PyScope.Exec(String code, IntPtr _globals, IntPtr _locals)
 bei Python.Runtime.PyScope.Exec(String code, PyDict locals)
 bei PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)

Yes, Cpython doesn’t have all the functionality with pyRevit like IronPython does. But back to the subject, did you restart the PC after changing the path?

And to add to the subject, I have been trying to install pywin32 also but there is some difficulty with packages that try to install other modules in themselves similar to the problem with Matplotlib I made some time ago here. So probably we’re at the same point, sorry I can’t help more than this. If someone could help us out :sweat_smile:

1 Like