mandiant/Ghidrathon

New Issue using Conda

Closed this issue · 9 comments

I am starting to get this issue with my plugin after installing ghidrathon.

ImportError: PyO3 modules may only be initialized once per interpreter process

can you provide some details so that we can reproduce the issue?

Yes! So I use conda to activate an environment, and then I created a custom package that I pip install (currently developing it), and then I open ghidra inside that environment. I am also on MacOS, so this may be Mac related w/ ghidrathon, but after I installed Ghidrathon, I started getting this error. It seems like when I run my script and import my python package, the second time I run it this error pops up, so the script only runs once successfully. I am not sure if ghidrathon is creating some kind of nested venv causing this issue?

Is it possible to restart the "scripting" environment from within ghidra? The only way for me to fix this is to kill ghidra every time, it kind of seems like the way it is running it is reimporting the libraries into an existing process. I don't get this error when I run the code via my command line outside of ghidra.

Thank you for reporting @cfossace. Based on the error that you listed this is likely a result of Jep’s use of a MainInterpreter that exists for the entire life of the process that created the first Python interpreter (in this case, Ghidra).

Can you try adding the name of your module to this file under “PYTHON_SHARED_MODULES” and rebuilding Ghidrathon before trying to import your module? If this still does not work we should float this issue upstream to see what the Jep developers have to say.

Yes! I will try this and report back.

So, I tried added my module name and the jep module name and rebuilding ghidrathon but I am still getting this error :( So if we can talk to the Jep developers that would be great!

Hello @cfossace - based on feedback from the Jep developers we just pushed a PR (#61) to switch Ghidrathon from using sub-interpreters to shared interpreters. This should enable the use of (C)Python modules that do not support sub-interpreters, e.g. pyo3. Could you test out the referenced PR to see if your issue is resolved?

The latest release fixes this issue in my local tests. Please reopen if you continue to experience issues with the latest release.