You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I'm currently trying to update Siconos, still for PlatRock usage. I know @fperignon that you worked hard on Siconos install / python package paths a few months ago, thanks for that. The documentation was improved as well, that's nice !
I'm using Poetry as python package manager but I get a python path-related error on Siconos import, that's why I have a suggestion. Note that the whole idea here is to improve the virtual envs managers compatibility, I'm aware that I could have used SICONOS_CUSTOM_INSTALL and ISOLATED_INSTALL cmake options, but that's not the point.
First, I compiled/installed Siconos successfully, with cmake telling me the two main paths:
The binaries, libraries and headers will be installed in /home/francois/PlatRock/.venv
Siconos python packages will be installed in /home/francois/PlatRock
The first (.venv) dir is the poetry virtual env I'm using with PlatRock / Siconos. Below that, I have classic bin,lib,include,... tree.
After that, I can import siconos within the virtual environment:
In [1]: importsiconosIn [2]: siconos.__file__Out[2]: '/home/francois/PlatRock/.venv/lib/python3.12/site-packages/siconos/__init__.py'
But the following fails, probably because of the way install paths are handled:
In [3]: importsiconos.kernelassk---------------------------------------------------------------------------ImportErrorTraceback (mostrecentcalllast)
CellIn[3], line1---->1importsiconos.kernelasskFile~/PlatRock/.venv/lib/python3.12/site-packages/siconos/kernel.py:2018# Import the low-level C/C++ module19if__package__or"."in__name__:
--->20from . import_sicpykernel21else:
22import_sicpykernelImportError: cannotimportname'_sicpykernel'from'siconos' (/home/francois/PlatRock/.venv/lib/python3.12/site-packages/siconos/__init__.py)
It turns out that _sicpykernel is installed in /home/francois/PlatRock/siconos, just like cmake tells. But as a consequence, siconos install is split into two folders, resulting in internal import issue.
The same procedure using venv instead of poetry works well, so I dug a little. With venv, the Siconos python package dir is different (note the full site-package path):
The binaries, libraries and headers will be installed in /home/francois/siconos/siconosenv
Siconos python packages will be installed in /home/francois/siconos/siconosenv/lib/python3.12/site-packages
Looking further in Siconos cmake files, I found here that PY_INSTALL_DIR relies on sys.path, more precisely on its last entry. With venv, the last entry is the site-package path, whereas in poetry the last entry is the virtual env root path, and this make _sicpykernel (and others) to reside in a place it is not found when locally importing them.
My suggestion is to use standard sysconfig.get_paths() instead of sys.path, which gives a dict with nice paths that seems consistent across different virtual env managers.
purelib key inside that looks like a good choice, but I didn't checked conda compatiblity.
As a conclusion, my suggestion in SiconosInstallSetup.cmake would be to replace L101: execute_process(COMMAND ${Python_EXECUTABLE} -c "import sys;print(sys.path[-1])" OUTPUT_VARIABLE PY_INSTALL_DIR)
with: execute_process(COMMAND ${Python_EXECUTABLE} -c "import sysconfig;print(sysconfig.get_paths()['purelib'])" OUTPUT_VARIABLE PY_INSTALL_DIR)
I'm not sure, but it may also be valid for conda, which would make IN_CONDA detection no longer necessary.
The text was updated successfully, but these errors were encountered:
thanks for the suggestion of sysconfig. It seems to fail when user do not work inside a virtual env (which is bad but sometimes happen ...). Anyway I think it's a good solution, especially if it works the same way for venv or conda-like installs. I'll have a deeper look into it.
Concerning you're installation problem, I'm a bit surprised. With main branch and a default conf when you run
cmake in an active python env (mamba, venv, ...), you should have something like :
e.g.
cmake -S -B build
...
- The binaries, libraries and headers will be installed in /home/francois/PlatRock/.venv
- Siconos python packages will be installed in /home/francois/PlatRock/.venv/lib/python3.12/site-packages
and after install something like:
ls /home/francois/PlatRock/.venv/lib/python3.12/site-packages/siconos
Hi,
I'm currently trying to update Siconos, still for PlatRock usage. I know @fperignon that you worked hard on Siconos install / python package paths a few months ago, thanks for that. The documentation was improved as well, that's nice !
I'm using Poetry as python package manager but I get a python path-related error on Siconos import, that's why I have a suggestion. Note that the whole idea here is to improve the virtual envs managers compatibility, I'm aware that I could have used
SICONOS_CUSTOM_INSTALL
andISOLATED_INSTALL
cmake options, but that's not the point.First, I compiled/installed Siconos successfully, with cmake telling me the two main paths:
The first (.venv) dir is the poetry virtual env I'm using with PlatRock / Siconos. Below that, I have classic bin,lib,include,... tree.
After that, I can import siconos within the virtual environment:
But the following fails, probably because of the way install paths are handled:
It turns out that _sicpykernel is installed in
/home/francois/PlatRock/siconos
, just like cmake tells. But as a consequence, siconos install is split into two folders, resulting in internal import issue.The same procedure using venv instead of poetry works well, so I dug a little. With venv, the Siconos python package dir is different (note the full
site-package
path):Looking further in Siconos cmake files, I found here that
PY_INSTALL_DIR
relies onsys.path
, more precisely on its last entry. With venv, the last entry is thesite-package
path, whereas in poetry the last entry is the virtual env root path, and this make_sicpykernel
(and others) to reside in a place it is not found when locally importing them.My suggestion is to use standard sysconfig.get_paths() instead of
sys.path
, which gives a dict with nice paths that seems consistent across different virtual env managers.purelib
key inside that looks like a good choice, but I didn't checked conda compatiblity.As a conclusion, my suggestion in SiconosInstallSetup.cmake would be to replace L101:
execute_process(COMMAND ${Python_EXECUTABLE} -c "import sys;print(sys.path[-1])" OUTPUT_VARIABLE PY_INSTALL_DIR)
with:
execute_process(COMMAND ${Python_EXECUTABLE} -c "import sysconfig;print(sysconfig.get_paths()['purelib'])" OUTPUT_VARIABLE PY_INSTALL_DIR)
I'm not sure, but it may also be valid for conda, which would make
IN_CONDA
detection no longer necessary.The text was updated successfully, but these errors were encountered: