Third-party libraries can be used by installing them locally and adding the site-packages directory to the environment variable PYTHONPATH before launching Revit.
This works perfectly fine after launching. However, after reloading pyRevit I get the following error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Anyone who faced the same issue and was able to track it down and solve it?
A bit be more specific: I encountered it when running Numpy (and libraries build on Numpy like Pandas and Scipy). With other libraries I did not have this problem.
Hi foaks, I am still facing this issue I am afraid. To be more precise, this is the traceback:
IronPython Traceback:
Traceback (most recent call last):
File "C:\ProgramData\pyRevit\base\extensions\pyRevitCore.extension\pyRevit.tab\pyRevit.panel\tools.stack\Reload.pushbutton\script.py", line 32, in <module>
File "C:\ProgramData\pyRevit\base\pyrevitlib\pyrevit\loader\sessionmgr.py", line 327, in reload_pyrevit
File "C:\ProgramData\pyRevit\base\pyrevitlib\pyrevit\loader\sessionmgr.py", line 285, in load_session
File "C:\ProgramData\pyRevit\base\pyrevitlib\pyrevit\loader\sessionmgr.py", line 105, in _perform_onsessionloadstart_ops
File "C:\ProgramData\pyRevit\base\pyrevitlib\pyrevit\loader\sessionmgr.py", line 57, in _clear_running_engines
StandardError: Exception has been thrown by the target of an invocation.
Script Executor Traceback:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
@eirannejad could this issue be related to the CPython engine not being closed properly in a previous session?
@Jean-Marc@eirannejad we have now a bunch of colleagues reporting this same issue and it is blocking development and usage of pyRevit Do either of you have a slight clue what is going wrong here? We would be happy to assist in debugging or fixing this.
Hi @GooseG ,
Sorry I did not have time to look further into this issue. I don’t realy need python 3 packages. To deal with dataframes I tend to use a process that involves exporting the data to whatever data storage (can be csv) then I use streamlit to create dashboards with all the neats features it has.
IMHO, I would not really count on a neat way to fix this issue nor to be able to deploy a solution that makes sense. But this is also a bit out of my league (for now I hope) in terms of coding and understanding the IN’s and OUT’s around this issue
The Exception in itself makes sense. It states that you basically cannot modify the engine using the reloading command as it is trying to read/writh the protected memory slot the engine is located. But like I said, out of my league to fix it.
Thanks for thinking along either way @Jean-Marc. Maybe, the issue is caused because we wrap the python 3 package as a pyRevit library extension. We can run a python 3 command or pushbutton that imports from this library extension.
But the problem already arises on startup, without even running or importing the package. So this implies that the problem is around pyRevit trying to load the library extension as an IronPython Library extension, instead of a Python 3 library extension.
We wrap the Python 3 packages as library extensions so we can share them easily among our users as extension dependencies. Is there perhaps another way to ship python 3 dependent libraries with an extension?
I am still having issues loading the Pandas, numpy, etc. Was wondering if I could run .exe program which wraps all the python3 libraries. I am using Pyinstaller to achieve this.