sebastiendfortier / conda_packaging

MSC project that provides a docker container to build RPN-SI libraries and python libraries to work with MSC standard files
GNU General Public License v3.0
2 stars 0 forks source link

Can't import RPN libraries in non-activated env. #1

Closed aulemahal closed 6 months ago

aulemahal commented 6 months ago

https://github.com/sebastiendfortier/conda_packaging/blob/6c2d21e04b90d34b39a284c48a6ca653fae32c02/conda_recipies/python-rpn/conda.recipe/etc/conda/activate.d/env_vars.sh#L1

I fully understand why you would use the activate hooks to set that variable, but this breaks a few setups that I think are more common than one would think:

In all of these cases, the conda environment that contains librmn and others is not actually activated before being used. Therefore, importing the python packages fails with something similar to :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/exec/pbourg/.conda/eccc/lib/python3.11/site-packages/fstpy/__init__.py", line 9, in <module>
    import rpnpy.librmn.all as rmn
  File "/exec/pbourg/.conda/eccc/lib/python3.11/site-packages/eccc_rpnpy-2.2.0rc3-py3.11.egg/rpnpy/librmn/__init__.py", line 115, in <module>
  File "/exec/pbourg/.conda/eccc/lib/python3.11/site-packages/eccc_rpnpy-2.2.0rc3-py3.11.egg/rpnpy/librmn/__init__.py", line 104, in loadRMNlib
OSError: [Errno -1] Failed to find librmn.so: : 'librmn.so'

I had the same problem with ESMF and it was fixed by making a guess about the library location if the env variable was not set. See : https://github.com/esmf-org/esmf/pull/151

The error could be fixed by adding os.path.join(sys.prefix, 'lib') to the list of paths in https://github.com/sebastiendfortier/python-rpn/blob/a72c862d37c28e9b9a67e7c8aa590c292808397e/lib/rpnpy/librmn/__init__.py#L93-L101

Does that make sense ? I could suggest a PR in the other repo, but I suspect github isn't the main.

(PS: Tu me le dis si tu préfères les courriels, ou le français)

sebastiendfortier commented 6 months ago

Totally forgotten about that.. damn. You are absolutly right! I didnt want to touch python-rpn, but that might be a better solution. Could you make the PR modification in python-rpn, I'll update the conda_packaging project. Thank you! spookipy, fstpy, ci_ftscomp and fstcatalog our on their way to be added