nasa / trick

Trick Simulation Environment. Trick provides a common set of simulation capabilities and utilities to build simulations automatically.
Other
26 stars 14 forks source link

Packages from Python Virtual Environment are not found #1728

Closed genti337 closed 1 month ago

genti337 commented 1 month ago

Trick does not seem to be picking up the packages that are installed in the Python Virtual environment. I tried reconfiguring and recompiling Trick with my virtual environment active and still no luck. I was able to get it to work by adding the path to the virtual environment packages to TRICK_PYTHON_PATH in my S_overrides.mk but that doesn't seem right.

TRICK_PYTHON_PATH += :${MODEL_PACKAGE_HOME}/landerVenv/lib/python3.12/site-packages

Is there something I'm missing with using Python virtual environments for Trick?

hchen99 commented 1 month ago

I did some quick tests on a Mac using Python virtual environment through conda and didn't seem to have an issue finding the Python packages installed when running a trick sim. However, I did need to add TRICK_LDFLAGS to S_overrides.mk to point to Python virtual env lib directory in order to make the sim executable regardless of virtual env active or not. Also, when running the trick sim, libpython3.12.dylib couldn't be found in the listed locations which didn't include the Python virtual lib folder. If libpython3.12.dylib was copied to an expected location, the sim ran and installed Python package such as numpy could be found.

Interesting that you needed to use TRICK_PYTHON_PATH to make it work.

Will be looking into this further.

sharmeye commented 1 month ago

We've discussed this further, and it seems to us that this is not really a Trick issue per se but more of a python configuration issue. We would suggest you set up your python virtual environment, install your dependencies in that environment, then run Trick in that environment. I'm glad you got it working with your method.

genti337 commented 4 weeks ago

Following up on this. Looking at config.status it appears that some of my references to python to are looking at the virtual environment while others are looking at the system python.

S["PYTHON_EXTRA_LIBS"]=""
S["PYTHON_LIBS"]="-L/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin -lpython3.12 -ldl -framework CoreFoundat"\
"ion -lpython3.12 -ldl -framework CoreFoundation "
S["PYTHON_CPPFLAGS"]="-isystem/opt/homebrew/opt/python@3.12/Frameworks/Python.framework/Versions/3.12/include/python3.12 -isystem/opt/homebrew/opt/python@3.12/Frameworks/"\
"Python.framework/Versions/3.12/include/python3.12"
S["PYTHON_CONFIG"]="/opt/homebrew/bin/python3.12-config"
S["PYTHON"]="/Users/jmgentil/sims/lander/landerVenv/bin/python3"
S["PYTHON_VERSION"]="3"

It looks like PYTHON_LIBS is pointing to the system version of python while the PYTHON is pointing to my virtual environment. I had the virtual environment active when I ran ./configure for Trick. Could this be why Trick couldn't find my Python virtual environment packages?

hchen99 commented 3 weeks ago

Could be. Maybe reinstall your virtual environment? I see PYTHON related entries in my config.log all point to my virtual environment.

hchen99 commented 2 weeks ago

Btw, may want to run make spotless and then ./configure if you have not tried so. Or try git clean -Xdf +./configure.