I’m reaching out for some assistance as I’ve encountered a couple of diffculties while working with CPython on the latest version of PyRevit. I tried to test it pyrRevitDev and Test Cpython Command
Has anyone else encountered a similar issue and successfully identified the root cause and solution? Any insights or assistance would be immensely appreciated!
can you please test what does the following code outputs?
#! python3
import sys
print(sys.path)
if you don’t see the PYTHONPATH directory you have set, you’ve discovered a bug!
From a quick search through the source code it seems that the pythonpath variable is read but not used while loading the cpython engine.
EDIT: I was wrong, the variable is loaded correctly by pyRevit.
the first problem should be mostly due to the order of which the search paths are added to sys.path; pyRevit’s own site-packages contains old/incompatible modules that gets loaded before the cpython 3 version.
I was able to run the test without having that issue (but it crashes a bit after) on revit 2022, cpython 3.8.5. What’s your revit and pyrevit version?
Thank you for response.
These are the outputs am getting but i am using python 3.7
#! python3
import sys
for i in sys.path:
print(i)
>>> D:\__DEV__\pyArep\pyAREP_dev.extension\PyYoussef.tab\Test_tools.panel\Test.pushbutton
D:\__DEV__\Check-it\Check-it_lib.lib
D:\__DEV__\pyArep\pyAREP_lib.lib
C:\Program Files\pyRevit-Master\pyrevitlib
C:\Program Files\pyRevit-Master\site-packages
C:\Program Files\Python37\Lib\site-packages
even after switching the python path to first index in sys.path list i can still not get to load the packages :
#! python3
import sys
sys.path.insert(0, "C:\Program Files\Python37\Lib\site-packages")
for i in sys.path:
print(i)
import numpy
>>>>C:\Program Files\Python37\Lib\site-packages
D:\__DEV__\pyArep\pyAREP_dev.extension\PyYoussef.tab\Test_tools.panel\Test.pushbutton
D:\__DEV__\Check-it\Check-it_lib.lib
D:\__DEV__\pyArep\pyAREP_lib.lib
C:\Program Files\pyRevit-Master\pyrevitlib
C:\Program Files\pyRevit-Master\site-packages
C:\Program Files\Python37\Lib\site-packages
CPython Traceback:
ModuleNotFoundError : No module named 'json'
File "D:\__DEV__\pyArep\pyAREP_dev.extension\PyYoussef.tab\Test_tools.panel\Test.pushbutton\script.py", line 10, in <module>
import numpy
File "C:\Program Files\Python37\Lib\site-packages\numpy\__init__.py", line 138, in <module>
from ._version import get_versions
File "C:\Program Files\Python37\Lib\site-packages\numpy\_version.py", line 7, in <module>
import json
pyRevitLabs.PythonNet
à Python.Runtime.Runtime.CheckExceptionOccurred()
à Python.Runtime.PyScope.Exec(String code, IntPtr _globals, IntPtr _locals)
à Python.Runtime.PyScope.Exec(String code, PyDict locals)
à PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)
I’m wondering if all this has somthing to do with this error :
Since python 3.7 reached is End of Life a while ago, I suggest you to move to 3.8.5
The next major pyRevit Release will also drop old python versions and focus on newer ones.
In the meantime, if you feel brave enough you can try the WIP version, in which I triend to solve a long standing issue with CPython and fixed the import order (so you don’t have to worry about it if you use the PYTHONPATH environment variable)
Mixing environments in the sys.path is a recipe for disaster!
drop all the sys.path.insert lines;
install your requirements in single python 3.8.5 environment;
either set the PYTHONPATH environment variable or a single sys.path.insert to the site-packages folder of that python 3.8.5 environment.
The wip version should already take care of loading the right paths.
A side note: when you use the raw string format (the r before the double quotes you don’t need to escape the backslashes.
Having that said, and as I’ve stated many times here in the forum, cpython support is basically broken in pyrevit, and will hopefully be fixed in the next major release