相关文章推荐
Two things you can test:
As said above try to use FreeCAD as Python module. This won't call the init() function because the interpreter is already initialized. So, try these lines:

Code: Select all

import FreeCADGui
FreeCADGui.showMainWindow()
FreeCADGui.exec_loop()
Then in the Python console of FreeCAD enter:

Code: Select all

import site
site.getsitepackages()
This should include all needed paths.
If you compile FreeCAD yourself then add

Code: Select all

config.isolated = 0;
config.user_site_directory = 1;
directly below the line

Code: Select all

PyConfig_InitIsolatedConfig(&config);
			
wmayer wrote: Wed Mar 20, 2024 3:31 pm Two things you can test:
As said above try to use FreeCAD as Python module. This won't call the init() function because the interpreter is already initialized. So, try these lines:

Code: Select all

import FreeCADGui
FreeCADGui.showMainWindow()
FreeCADGui.exec_loop()
Then in the Python console of FreeCAD enter:

Code: Select all

import site
site.getsitepackages()
This should include all needed paths.
If you compile FreeCAD yourself then add

Code: Select all

config.isolated = 0;
config.user_site_directory = 1;
directly below the line

Code: Select all

PyConfig_InitIsolatedConfig(&config);
Thanks for all the detail. 
from my freecad-build-master/bin/ :

Code: Select all

>>> import FreeCADGui
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'FreeCADGui'
typo ?
I just edited Interpreter.cpp

Code: Select all

void initInterpreter(int argc, char* argv[])
    PyStatus status;
    PyConfig config;
    PyConfig_InitIsolatedConfig(&config);
    config.isolated = 0;
    config.user_site_directory = 1; // ### fix missing /usr/local/lib* paths
ran make , but it did not seem to fix it.  FreeCAD python console:

Code: Select all

>>> import site
>>> site.getsitepackages()
['/usr/lib64/python3.11/site-packages', '/usr/lib/python3.11/site-packages']
I hope I got that right. (Or rather, I hope I got it wrong and your fix will work when I do it right ;)  ).
wmayer wrote: Wed Mar 20, 2024 4:17 pm You must switch to your lib directory and then call ../bin/FreeCAD. This way FreeCADGui.so is already in the search path. Thanks, I get it now.

Code: Select all

>>> FreeCADGui.showMainWindow()
>>> FreeCADGui.exec_loop()
FC python console:

Code: Select all

>>> import site
>>> site.getsitepackages()
['/usr/local/lib64/python3.11/site-packages', '/usr/local/lib/python3.11/site-packages', '/usr/lib64/python3.11/site-packages', '/usr/lib/python3.11/site-packages']
That seems to work fine.
Yes, I saw that. Is that any different from what I added to my local master and which did not seem to fix the problem?
viewtopic.php?p=748385#p748345
I have a local build of Py 3.12 and with these changes

Code: Select all

import site
site.ENABLE_USER_SITE
gives true. Without the changes it's false.
Ah, hang on. I just checked the build process and it looks like it did not complete due to a change in qt5 earlier today.
I've just run make clean. Back in 3h when I get a new clean build. ......
OK, I can confirm this patch fixes the path issue on my fedora38 / python 3.11 system . :)
Many thanks to wmayer for digging into this and finding a solution.
 
推荐文章