BookmarkSubscribe
Choose Language Hide Translation Bar
pmroz
Super User

How to configure Python for JMP 14?

I'm very new to Python so this is hopefully an easy question.  I have Python version 3.6 and 3.7 installed.  I installed numpy, matplotlib, scipy and pdfkit in both versions.  However I get errors in the log window when trying to run examples from the scripting index.

For the Python Get example:

Names Default To Here( 1 );
Python Init();
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();

I get the following errors:

//:*/
Names Default To Here( 1 );
Python Init();
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();
/*:

/**********/
# Read a binary file containing doubles into an ndarray
x1 = _JMPnp.fromfile("C:\\Users\\pmroz\\AppData\\Local\\Temp\\eacac6a7-dd5e-4ceb-dcbd0248455fb787.csv", dtype=_JMPnp.float64, count=-1, sep="")
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
NameError: name '_JMPnp' is not defined

x1 = [1, 2, 3];
x2 = .;
/**********/
# Import a JMP exported .csv file into a Data Frame
dt1 = _JMPpd.read_csv("C:\\Users\\pmroz\\AppData\\Local\\Temp\\8b6475be-aaf0-408b-d1cae4522f253881.csv")
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
NameError: name '_JMPpd' is not defined

Send Expects Scriptable Object in access or evaluation of 'Send' , dt2 <<  /*###*/New Data View/*###*/

In the following script, error marked by /*###*/
Names Default To Here( 1 );
Python Init();
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 <<  /*###*/New Data View/*###*/;
Close( dt1 );
Python Term();

What am I missing?  Thanks.

0 Kudos
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: How to configure Python for JMP 14?

First I want to apologize for the trouble you are having with JMP's python support.  The original developer of the Python feature retired at the end of JMP 14's development cycle. I am working my way through the code to fix the outstanding issues.

 

There are issues with JMP's ability to locate Python.  If JMP finds it by itself you are good to go, usually if you only have one version of Python on your system you will be fine.  When it fails, it is difficult to work around the issue in current JMP releases. Additionally there are differences between Windows and Mac in how well or how poor it is at finding Python. I have uncovered a couple of bugs in the code that is supposed to let you specify where your instance of Python is located.

 

Use the Python sys path( {"",...} ) within Python Init() works on JMP for Mac v14.1 or newer, but is broken on JMP 14.0, 14.1 for Windows.

 

Windows JMP does not handle it well if there is more than one version of Python on the system. You need to specify the version of Python to use within the Python Init ( Use Python Version("3.6"));   for example to select the 3.6 version.  Even with this specified you still may get errors to the log on locating modules that JMP tries to load to provide interoperability.  On the Mac JMP 14.0 will have issues if there is more than 1 version of Python3.  Mac JMP 14.1 fixes this by using the highest version of Python 3, rather than bailing out if there is more than one.

 

On my Mac where Python 3.6 is installed in /Library/Frameworks/Python.framework, my Python Init() statement is:

Python Init( Path("/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib"), Use Python Version("3.6") );

 

The Path() statetment works on Mac, but not Windows...

 

On my Windows 10 desktop I have installed Anaconda with Python 3.6 in my C:\local\anaconda3 directory.

 

The following script runs for me, even though it kicks out the warnings of not finding the modules. To solve the module loading issue, the first thing I do after the init is to import the sys module and then set sys.path to the path value that would be returned if you do the following within the python interpreter, then load those modules within my script before continuing on.

 

Locating your sys.path from the python interpreter.

C:\local\anaconda3>.\python.exe
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print (sys.path)
['', 'C:\\local\\anaconda3\\python36.zip', 'C:\\local\\anaconda3\\DLLs', 'C:\\local\\anaconda3\\lib', 'C:\\local\\anaconda3', 'C:\\local\\anaconda3\\lib\\site-packages', 'C:\\local\\anaconda3\\lib\\site-packages\\win32', 'C:\\local\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\local\\anaconda3\\lib\\site-packages\\Pythonwin']
>>>

 

My modified script:

 

Names Default To Here( 1 );
Python Init(Use Python Version("3.6"));
Python Submit("\[
import sys
sys.path=['', 'C:\\local\\anaconda3\\python36.zip', 'C:\\local\\anaconda3\\DLLs', 'C:\\local\\anaconda3\\lib', 'C:\\local\\anaconda3', 'C:\\local\\anaconda3\\lib\\site-packages', 'C:\\local\\anaconda3\\lib\\site-packages\\win32', 'C:\\local\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\local\\anaconda3\\lib\\site-packages\\Pythonwin']
import numpy as _JMPnp
import scipy as _JMPsp
import pandas as _JMPpd
import sqlite3 as _JMPsq
]\");
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();

 

 

With the following output in the log

 

/**********/
# Import the numpy module for array and matrix support
import numpy as _JMPnp
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'numpy'
/**********/
# Import the scipy module for scientific computing support
import scipy as _JMPsp
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'scipy'
/**********/
# Import the pandas module for Series/Data Frame support
import pandas as _JMPpd
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'pandas'
/**********/
# Import the matplotlib module for 2D plotting
import matplotlib as _JMPmpl
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'matplotlib'
/**********/
# Import the matplotlib.pyplot module for plots
import matplotlib.pyplot as _JMPpp
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'matplotlib'
/**********/
# Set the matplotlib.pyplot interactive flag to false
_JMPpp.interactive(False)
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
NameError: name '_JMPpp' is not defined
Unable to import the 'numpy' Python module
Unable to import the 'scipy' Python module
Unable to import the 'pandas' Python module
Unable to import the 'matplotlib' Python module


x1 = [1, 2, 3];
x2 = [1, 2, 3];
0

 

 

Tested against JMP 14.1 and current development.  

 

Again on behalf of JMP Development, I apologize for the raw state of the Python support.  Please bear with us as we continue to fix and improve this important feature. Please report problems you find and suggestions for new features.  

 

Thanks.

Re: How to configure Python for JMP 14?

Of course, after I post I find a better way, but it involves setting an environment variable.  JMP 14 is looking for an environment variable.  It is the sys.path that I described in the previous post, however you need to set to be a JSL List of paths.  On Windows 10, you need to go to system properties, Advanced System Settings, Environment Variables and create a new Environment Variable.

 

 

Variable Name:    Python sys path
Variable Value:    {"", "C:\\local\\anaconda3\\python36.zip", "C:\\local\\anaconda3\\DLLs", 
"C:\\local\\anaconda3\\lib", "C:\\local\\anaconda3", "C:\\local\\anaconda3\\lib\\site-packages", 
"C:\\local\\anaconda3\\lib\\site-packages\\win32", 
"C:\\local\\anaconda3\\lib\\site-packages\\win32\\lib", 
"C:\\local\\anaconda3\\lib\\site-packages\\Pythonwin"}

 

 

Which then allows this script

Names Default To Here( 1 );
Python Init(Use Python Version("3.6"));
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();

 

To give the expected

 

x1 = [1, 2, 3];
x2 = [1, 2, 3];
0

 

 

 PythonSysPath.JPG

 

11 REPLIES 11
stephen_pearson
Community Trekker

Re: How to configure Python for JMP 14?

I have JMP Pro 14.0 and Anaconda 1.8.7 installed and can get that code to run. the _JMPxx, refers to numpy: np, pandas: pd and matplotlib.pyplot: pp. It seems pandas may be a dependency.

I get a warning about "Unable to import the 'matplotlib.pyplot' Python module", the first time I run the first 6 lines of code, but if I rerun them, no error appears in the log.
0 Kudos

Re: How to configure Python for JMP 14?

First I want to apologize for the trouble you are having with JMP's python support.  The original developer of the Python feature retired at the end of JMP 14's development cycle. I am working my way through the code to fix the outstanding issues.

 

There are issues with JMP's ability to locate Python.  If JMP finds it by itself you are good to go, usually if you only have one version of Python on your system you will be fine.  When it fails, it is difficult to work around the issue in current JMP releases. Additionally there are differences between Windows and Mac in how well or how poor it is at finding Python. I have uncovered a couple of bugs in the code that is supposed to let you specify where your instance of Python is located.

 

Use the Python sys path( {"",...} ) within Python Init() works on JMP for Mac v14.1 or newer, but is broken on JMP 14.0, 14.1 for Windows.

 

Windows JMP does not handle it well if there is more than one version of Python on the system. You need to specify the version of Python to use within the Python Init ( Use Python Version("3.6"));   for example to select the 3.6 version.  Even with this specified you still may get errors to the log on locating modules that JMP tries to load to provide interoperability.  On the Mac JMP 14.0 will have issues if there is more than 1 version of Python3.  Mac JMP 14.1 fixes this by using the highest version of Python 3, rather than bailing out if there is more than one.

 

On my Mac where Python 3.6 is installed in /Library/Frameworks/Python.framework, my Python Init() statement is:

Python Init( Path("/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib"), Use Python Version("3.6") );

 

The Path() statetment works on Mac, but not Windows...

 

On my Windows 10 desktop I have installed Anaconda with Python 3.6 in my C:\local\anaconda3 directory.

 

The following script runs for me, even though it kicks out the warnings of not finding the modules. To solve the module loading issue, the first thing I do after the init is to import the sys module and then set sys.path to the path value that would be returned if you do the following within the python interpreter, then load those modules within my script before continuing on.

 

Locating your sys.path from the python interpreter.

C:\local\anaconda3>.\python.exe
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print (sys.path)
['', 'C:\\local\\anaconda3\\python36.zip', 'C:\\local\\anaconda3\\DLLs', 'C:\\local\\anaconda3\\lib', 'C:\\local\\anaconda3', 'C:\\local\\anaconda3\\lib\\site-packages', 'C:\\local\\anaconda3\\lib\\site-packages\\win32', 'C:\\local\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\local\\anaconda3\\lib\\site-packages\\Pythonwin']
>>>

 

My modified script:

 

Names Default To Here( 1 );
Python Init(Use Python Version("3.6"));
Python Submit("\[
import sys
sys.path=['', 'C:\\local\\anaconda3\\python36.zip', 'C:\\local\\anaconda3\\DLLs', 'C:\\local\\anaconda3\\lib', 'C:\\local\\anaconda3', 'C:\\local\\anaconda3\\lib\\site-packages', 'C:\\local\\anaconda3\\lib\\site-packages\\win32', 'C:\\local\\anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\local\\anaconda3\\lib\\site-packages\\Pythonwin']
import numpy as _JMPnp
import scipy as _JMPsp
import pandas as _JMPpd
import sqlite3 as _JMPsq
]\");
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();

 

 

With the following output in the log

 

/**********/
# Import the numpy module for array and matrix support
import numpy as _JMPnp
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'numpy'
/**********/
# Import the scipy module for scientific computing support
import scipy as _JMPsp
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'scipy'
/**********/
# Import the pandas module for Series/Data Frame support
import pandas as _JMPpd
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'pandas'
/**********/
# Import the matplotlib module for 2D plotting
import matplotlib as _JMPmpl
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'matplotlib'
/**********/
# Import the matplotlib.pyplot module for plots
import matplotlib.pyplot as _JMPpp
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'matplotlib'
/**********/
# Set the matplotlib.pyplot interactive flag to false
_JMPpp.interactive(False)
/**********/
Traceback (most recent call last):
  File "<string>", line 2, in <module>
NameError: name '_JMPpp' is not defined
Unable to import the 'numpy' Python module
Unable to import the 'scipy' Python module
Unable to import the 'pandas' Python module
Unable to import the 'matplotlib' Python module


x1 = [1, 2, 3];
x2 = [1, 2, 3];
0

 

 

Tested against JMP 14.1 and current development.  

 

Again on behalf of JMP Development, I apologize for the raw state of the Python support.  Please bear with us as we continue to fix and improve this important feature. Please report problems you find and suggestions for new features.  

 

Thanks.

Re: How to configure Python for JMP 14?

Of course, after I post I find a better way, but it involves setting an environment variable.  JMP 14 is looking for an environment variable.  It is the sys.path that I described in the previous post, however you need to set to be a JSL List of paths.  On Windows 10, you need to go to system properties, Advanced System Settings, Environment Variables and create a new Environment Variable.

 

 

Variable Name:    Python sys path
Variable Value:    {"", "C:\\local\\anaconda3\\python36.zip", "C:\\local\\anaconda3\\DLLs", 
"C:\\local\\anaconda3\\lib", "C:\\local\\anaconda3", "C:\\local\\anaconda3\\lib\\site-packages", 
"C:\\local\\anaconda3\\lib\\site-packages\\win32", 
"C:\\local\\anaconda3\\lib\\site-packages\\win32\\lib", 
"C:\\local\\anaconda3\\lib\\site-packages\\Pythonwin"}

 

 

Which then allows this script

Names Default To Here( 1 );
Python Init(Use Python Version("3.6"));
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();

 

To give the expected

 

x1 = [1, 2, 3];
x2 = [1, 2, 3];
0

 

 

 PythonSysPath.JPG

 

Rob128
Community Trekker

Re: How to configure Python for JMP 14?

Hi Paul,
Thanks for your work, unfortunately I just have JMP version 13.0. And I work with Python version 3.7.1 without Anaconda.
I have all the libraries needed ( numpy, scipy, matplotlib, panda... ).
I am on windows 10, I did your "variable name" trick (that is well explained by the way) but with this piece of code I'm struggling...
Have a look at it instead :

 

Names Default To Here( 1 );
Python Init(Use Python Version("3.7.1"));
/*Python Submit("\[
import sys
sys.path=['', 'C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
'C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
'C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
'C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python37-32',
'C:\\Users\\username\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages']
import numpy as _JMPnp
import scipy as _JMPsp
import pandas as _JMPpd
import sqlite3 as _JMPsq
]\");
*/
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();

Remark : Python Init is not in blue font.

The log window displays :

Name Unresolved: Python Init in access or evaluation of 'Python Init' , Python Init( Use Python Version( "3.7.1" ) ) /*###*/

In the following script, error marked by /*###*/
Names Default To Here( 1 );
Python Init( Use Python Version( "3.7.1" ) ) /*###*/;
x1 = [1, 2, 3];
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
dt2 = Python Get( dt1 );
dt2 << New Data View;
Close( dt1 );
Python Term();




Thanks for reading :)

Robin

0 Kudos
pmroz
Super User

Re: How to configure Python for JMP 14?

I thought that the Python interface wasn't available until JMP 14.

Rob128
Community Trekker

Re: How to configure Python for JMP 14?

I though it is, because my .py which is just a print of Hello world works with this jsl : 

dt = current data table();
txt  = runprogram(executable("C:\Users\username\AppData\Local\Programs\Python\Python37-32\python.exe"), 
        options({"C:\Users\username\PycharmProjects\FormationPython\tp1.py"}), 
        readfunction("text"));
//pythconn<<Get Version;

 And the log  :

 

//:*/
dt = current data table();
txt = runprogram(executable("C:\Users\username\AppData\Local\Programs\Python\Python37-32\python.exe"),
options({"C:\Users\username\PycharmProjects\FormationPython\tp1.py"}),
readfunction("text"));
//pythconn<<Get Version;

/*:
"Hello World
"

 

0 Kudos
stan_koprowski
Community Manager Community Manager

Re: How to configure Python for JMP 14?

Hi @Rob128,

The Use of a full 2-way connection to Python via a local install of Python which allows JMP to send data to Python, execute Python code from a JSL script, 
return data and results from Python programs, and interactively explore Python results in JMP was introduced in JMP 14.

 

As you have demostrated using JMP 13 (with Run Program) you can control an external program using stdin and stdout.

 

The comments from @Paul_Nelson are referring to the JMP 14 implementation of the full 2-way connection to Python and not via Run Program.

 

HTH,

Stan

GM1
GM1
New Contributor

Re: How to configure Python for JMP 14?

Hi Paul,

 

I am just trying to send a datatable to Python. However, all columns end up in one string column with the actual columns separated by \t (see picture). Any idea what goes wrong here? Do you need a special pandas version (or a special matplotlib version, as this also causes an error)?

Regarding the configuration of Python it would be great if one could select a conda environment which should be used.

JMP_Python.PNG

Regards

Gerd

0 Kudos

Re: How to configure Python for JMP 14?

You need to set your Python Init(), and/or  your system environment variables, to point ot the conda installation.  See the earlier responses to this community posting. There are examples of both setting the parameters withing the Python Init(), and setting environment variables to point to you python installation.