Hello,
I have some DB in an xlsx file, that I need to access from my macro on pyrevit.
For that i imported openpyxl module (which is already installed from PIP).
But i have the following message error on shell console:
ImportError: No module named openpyxl
Thank you Steve for your prompt reply.
What I can say that the method you propose need that Excel or Office is already installed on windows. So it’s dependent in someway to the softwares on each PC.
I have seen that in one forum that Ehsan Iran-Nejad has already implemented on the packaged CPython: xlrd and xlsxwriter modules. The first is outdated now and don’t give access to the new file format of excel. The second is nice and rich but can only create new xlsx file but can’t modify existing one’s.
openpyxl seem to be capable to do all that in one unique module: read, modify, create, write. And seem to be enough active.
So a general question, is it possible to import 3rd party modules non already packaged in CPython of pyrevit?
If it’s possible? how it can be done?
I will try to explain the procedure for who need it:
In fact, since pyrevit 4.7 version, it’s possible to use CPython instead of IronPython, letting us to use more common modules that are not compatible with IronPython. To do that, we have to force the script to use CPython by adding this line:
#! python3
at the first line of the script.
More over, we have to add on windows system variable environment, the key PYTHONPATH pointing to the site-packages folder of your CPython version installed. This key can be added through advanced parameter manager:
A restart ow windows should be done to make this setting effective.
Be aware that the imported module is compatible with the version installed in the package of pyRevit and have the same revision. for example 3.8.* or 3.7.*