Sometimes JMP has trouble locating the correct version of Python. The first thing to try is running Python from the command line. If Python doesn’t run from a terminal or console window, something is wrong with the Python installation.
Note: Before you proceed with troubleshooting, verify that you’re running a supported version of Python. See Install Python.
JMP delays loading Python until a JSL-based script requires access to it. When JMP loads Python, it needs to be able to find the Python shared library and any of the shared libraries that the Python DLL depends on. Once the Python interpreter is loaded, Python needs to be able to find the distribution’s standard Python modules. To guide this process, JMP uses registry entries, environment variables, and user-specified paths.
Python also looks for certain environment variables. Avoid using any user-specified paths or environment variables, and let JMP find Python in the registry. The following methods help JMP locate Python if the automatic location doesn’t work:
• JMP_PYTHON_MODULE_PATH is a JMP-specific version of PYTHONPATH. This variable is the replacement for Python Sys Path. In JMP_PYTHON_MODULE_PATH, specify standard OS paths. Separate the paths with a colon on macOS. Separate the paths with a semicolon on Windows.
• JMP_LIB_PYTHON_PATH is a JMP-specific version of PYTHONHOME. The variable contains the full path to the Python shared library, or the parent directory to the shared library.
Windows finds Python in the following order of precedence:
1. JMP looks at the environment variables Python Sys Path (deprecated), PYTHONINSTALLPATH (deprecated), and JMP_PYTHON_MODULE_PATH, in that order. JMP uses the first variable that is found.
2. JMP checks JMP_LIB_PYTHON_PATH for a path to the Python shared library.
3. JMP checks for options that are specified in the Python Init() or Python Connect() function calls. Path() corresponds to the location of the Python shared library. Use Python Version() allows you to specify the version of Python to look for.
Python Sys Path provides the mechanism to set Python’s sys.path variable. If present, script parameters take precedence over the environment variables. There is one caveat. After JMP loads the Python shared library, the library is unloaded only when JMP shuts down. As a result, the Path() portion is only effective on the first load of Python, and does not allow for running different versions of Python in different scripts without shutting down JMP and restarting.
4. JMP reads the Windows registry to determine if Python has been installed. It looks at appropriate locations based on whether the installation was for an individual user or for all users on the Windows machine. If you have specified a Python version, other versions of Python will not be considered.
If JMP cannot locate Python, try the following option in the Python Init() expression:
Python Init( Init Trace( "TRUE" ) );
JMP prints details to the log about where it detects Python, including paths and registry entries for Python.
Typically, JMP determines the equivalent to the PYTHONHOME environment variable automatically if it is defined in the Windows registry.
Computer\<root>\SOFTWARE\Python\PythonCore\<version>\InstallPath
<root> is either the root key HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER depending on where and how you installed Python. <version> is the Python version number.
If multiple versions of Python are installed on your computer, you must specify which installation for JMP to use.
• The easiest method is to specify the version using the Use Python Version() argument in Python Init() or Python Connect() functions.
• Use the Path("path to an installed Python DLL or shared library") argument with the Python Init() or Python Connect() function.
• Define the JMP_LIB_PYTHON_PATH environment variable as described below.
Create the variable in your system environment variables using the Control Panel.
1. Select Start > Control Panel > System > Advanced system settings.
2. Click Environment Variables.
3. In the System variables pane, click New.
4. Type JMP_LIB_PYTHON_PATH for the Variable name.
5. Type the path to the Python<version>.dll file, for example:
C:/Program Files/Python/<version>/Python<version>.dll
6. Click OK and click OK again to close the System Properties window.
Locating Python on the Mac works the same as on Windows except for the step of looking in the registry. JMP looks in a couple of typical installation directories so see if it can locate Python. Python typically installs in /Library/Frameworks/Python.framework. A compatible version of Python located in the standard system location should work without any changes to environment variables or parameters passed to JSL.
If Python is installed in an alternate location, set configuration variables in your shell environment as needed. JMP on macOS uses the same environment variables as described in How JMP Finds Python on Windows.
JMP_LIB_PYTHON_PATH is the path to the Python shared library libpython3.x.dylib, where x is the minor version. If environment variables are needed, you typically only need to set JMP_LIB_PYTHON_PATH.
If JMP is unable to find install Python packages, you might also need to set the variable JMP_PYTHON_MODULE_PATH. The JMP_PYTHON_MODULE_PATH contains the same paths that the Python call print(sys.path) outputs. When you set an environment variable, use host OS path conventions. When the variable is passed in JSL, use a JSL list.
One way is to have Python tell you what it thinks its sys.path should be. In the example in this section, the same Python commands can be run on Windows to determine sys.path.
In the terminal or console window, enter the following boldface commands to get a string that specifies the location of the Python packages:
MDz320:~ shlori$ python --version
Python 3.6.4 :: Anaconda, Inc.
MDz320~ shlori$ python3
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
[’’, ’/anaconda3/lib/python36.zip’, ’/anaconda3/lib/python3.6’, ’/anaconda3/lib/python3.6/lib-dynload’, ’/anaconda3/lib/python3.6/site-packages’, ’/anaconda3/lib/python3.6/site-packages/aeosa’]
To test that your computer is able to run JSL scripts that use Python, run the following script:
Python Init();
Python Submit( "\[basket = ['apple', 'orange', 'pear']
print(basket)]\" );
Python Term();
You should see the following output in the log:
['apple', 'orange', 'pear']
0