cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
PeterChuang
Level I

Why does JMP JSL remove /usr/local/bin (and other paths) from Python os.environ['PATH'] on MacOS?

Issue statement:

 

-- On Mac OS, when JSL launches Python interpreter, it removes /use/local/bin and other paths from os.environ['PATH']

 

How to reproduce this issue:

 

-- For the following Python codes

import os
print(os.environ)

-- If the codes are executed in Mac OS Terminal, the results would be the followings:

(Note: only 'PATH' item is shown below. Other irrelevant items are not shown)

environ({  'PATH':'/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin:/opt/X11/bin'})

-- If the codes are executed in JSL (see JSL codes below)

Python Init();

python_codes =
"
import os print(os.environ) "; Python Init(); Python Submit (python_codes); Python Term();

The results will be

environ({ 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin'})

Question:

  1. Why does JMP/JSL remove these paths?
  2. Is there a way to make JMP/JSL honor the path settings from the shell, other than manually modifying the 'PATH' settings in JSL Python codes?
1 REPLY 1

Re: Why does JMP JSL remove /usr/local/bin (and other paths) from Python os.environ['PATH'] on MacOS?

JMP's Python sees the same environment variables that JMP itself sees.  The Python's shared library is loaded within JMP's process space so JMP's Python will only see what JMP sees.  You can verify this by running the following JSL.

 

path = Get Environment Variable("PATH");

 

What you get from JSL, and what you get from os.environ should be the same.

 

The real question is why JMP see's different path than the console...  You have have to remember the shell environment processes .login, .profile, .bashrc, .zshrc, ...  files before you get to the command line.  Second, the GUI launch environment does not process those files.  It may process the ~/.login or ~/.profile files but after a change you would have to log out first and log back in for changes to the login shell init files to be processed.

 

If you need such paths you can add them to the PATH within Python by updating os.environ within the script. That should only update what Python sees as the environment variables, and not alter the shell environment outside of JMP.