CPython and PyRevit

Hello All,

first of all, this question might be repetitive. if so, please point me to the right solution.

Here is my question: I need to use CPython to have access to libraries such as numpy and pandas. At the same time, I want to take advantage of Pyrevit’s capabilities such as forms etc. As far as I understood, I can’t have both of these on a single script file. If I got this correctly, is there any way to do this?

Thanks in advance

Hi @Ped_ra ,
unfortunately this is not possible at the moment, the pyrevit lib is still not completely compatible with CPython, so you can’t access things like logging and forms.

A really bad workaround to do GUIs for now is to write the old WinForms Form classes, or use the tkinter python library.

I will try to get CPython working in my spare time, watch for updates on this github issue.

Hi @sanzoghenzo,

Thanks for your input. I’m looking forward to your updates.
You’re right, there are some limitations to doing so thanks to the existing situation. However, I recently noticed that we can take advantage of Python subprocess to make this work. I’ll share a practical example on my GitHub very soon, but the links below can provide enough details on implementing this. I tried this solution and confirm that it’s functional.
Link 1: pyRevit - Dynamo Incompatibility: Two versions of Same DLL · Issue #1731 · eirannejad/pyRevit · GitHub
Link 2: subprocess — Subprocess management — Python 3.11.4 documentation

I hope this solution helps others too.

2 Likes

hi @sanzoghenzo - I found this question and am wondering something similar. Were you able to get tkinter to work? ~~ I’m not sure how to install packages (namely tkinter) in such a way where CPython can use and see it. Is there specific location I should install things to? Any thoughts here would be appreciated, thank you!~~

EDIT: I see some notes for installing things into site-packages on the forum - still wondering if you were able to get tkinter UI components to run as well

Hi @tigsss, welcome to the forum!

Unfortunately I didn’t try to use tkinter, it was just a guess. I went with the easy route and used winform for the little widget I had to create.

For portability, instead of trying to add libraries to the site-packages folder, create a .lib extension folder (search this forum or the developer docs for more info). The trick is to collect all the dependencies of the library; for packages installable via pip is as easy as create a virtual environment, install the package and copy the contwnts of site-packages; but for python standard libraries it is harder (if possible at all). I offered tkinter solution on the wron assumption it was already there…

And unfortunately I dont have news on the cpython front either, never got the time and willpower to tackle it :sweat_smile: