Page 1 of 1

Configure Python interpreter used by SeaDAS

Posted: Mon Feb 06, 2023 3:24 pm America/New_York
by icarroll
How do I configure SeaDAS to use a particular Python interpreter? Currently the "SeaDAS-Toolbox" > "Software & System Info..." window shows:

```
-----------------------------------------------------------
Main Application Platform:
-----------------------------------------------------------
Application Version: SeaDAS 8.3.0
SNAP Engine Version: 9.0.3* (SeaDAS Platform modified)
SNAP Desktop Version: 9.0.3* (SeaDAS Platform modified)
SNAP Engine Build Date: 202212081832
SNAP Desktop Build Date: 202212081837
...snipped...
Python3 Directory: /usr/local/bin/python3
```
I need to SeaDAS to use a different Python3 Directory. I have an existing Python virtual environment that has the requests package needed by SeaDAS, but I can't find documentation on how to point SeaDAS to a different Python3 Directory.

Thanks!

Re: Configure Python interpreter used by SeaDAS

Posted: Tue Feb 07, 2023 12:18 pm America/New_York
by OB SeaDAS - xuanyang02
If you can use /usr/local/bin/python3 for SeaDAS, it might be easier just to do

Code: Select all

/usr/local/bin/pip3 install requests
.
Otherwise add

Code: Select all

export PATH="/usr/local/bin:$PATH"
to your bash or zsh file, start a new terminal, and start SeaDAS in that terminal.

Re: Configure Python interpreter used by SeaDAS

Posted: Tue Feb 07, 2023 1:01 pm America/New_York
by gnwiii
icarroll wrote: Mon Feb 06, 2023 3:24 pm America/New_York I have an existing Python virtual environment that has the requests package needed by SeaDAS, but I can't find documentation on how to point SeaDAS to a different Python3 Directory.
You didn't mention which of the many virtual environments you use, but just run SeaDAS from the shell prompt in a terminal with the Python environment that provides the requests package, see: https://realpython.com/python-virtual-environments-a-primer/#activate-it.

Re: Configure Python interpreter used by SeaDAS

Posted: Tue Feb 07, 2023 2:59 pm America/New_York
by icarroll
The $PATH set by the Python virtual environment does not appear to affect SeaDAS. After the following, the "Python3 Directory" has not changed from what I posted above.

```
(venv-py3.10) $ which python
/path/to/venv-py3.10/bin/python
(venv-py3.10) $ which python3
/path/to/venv-py3.10/bin/python3
(venv-py3.10) $ ~/Applications/SeaDAS/bin/seadas
```

The answers indicate there is not a way to configure SeaDAS. I'll keep trying ways to make it recognize the PATH variable set by the virtual environment.

@gnwii I use Python's own venv, not conda, in case that's what you were wondering.
@OB SeaDAS - xuanyang02 I do not mess with /usr/local/bin. I only let Homebrew do that. As a fallback though, I will `/usr/local/bin/python3 -m pip install --user requests`.

Re: Configure Python interpreter used by SeaDAS

Posted: Mon Feb 13, 2023 11:24 am America/New_York
by gnwiii
@gnwii I use Python's own venv, not conda, in case that's what you were wondering.
See: https://whiteboxml.com/blog/the-definitive-guide-to-python-virtual-environments-with-conda. I'm currently using Fedora Linux, which provides an immutable conda base environment, no connection to Anaconda Python.

Starting SeaDAS 8 from the command line in a terminal with a conda env active "works for me", but macOS has been messing with the way the PATH is set for Finder Applications:
https://apple.stackexchange.com/questions/51677/how-to-set-path-for-finder-launched-applications has examples for many macOS versions. It seems the easy solution is to have a python in the default path with requests, so the suggestion to install requests for your /usr/local/bin/python3 should work.

Re: Configure Python interpreter used by SeaDAS

Posted: Tue May 09, 2023 9:43 am America/New_York
by nafi_ullah
you will need to modify the seadas_setup.sh script, which is used to set up the SeaDAS environment variables. Here are the steps you can follow:

Locate the seadas_setup.sh script. This script is typically located in the SeaDAS installation directory, under the ocssw subdirectory.

Open the seadas_setup.sh script in a text editor.

Locate the line that sets the OCSSW_PYTHON environment variable. By default, this line will look like this:

export OCSSW_PYTHON=/usr/bin/python
This line sets the OCSSW_PYTHON environment variable to use the system Python interpreter.

Modify the OCSSW_PYTHON environment variable to point to the Python interpreter that you want to use. For example, if you want to use a Python virtual environment located at /path/to/venv, you can set the OCSSW_PYTHON environment variable like this:


export OCSSW_PYTHON=/path/to/venv/bin/python
This will make SeaDAS use the Python interpreter located in the virtual environment.

Save the seadas_setup.sh script.

Restart any open SeaDAS terminals or shells to ensure that the new environment variables take effect.

After following these steps, SeaDAS should be configured to use the Python interpreter that you specified. You can confirm that SeaDAS is using the correct Python interpreter by running the python command within the SeaDAS environment and verifying that it is using the expected Python version and packages.
To know more about this kind of setup with find visit: https://www.enablegeek.com/tutorial_series/python/