Publication date: 07/08/2024

Python Integration Functions

Python Connect()

Description

Returns an active Python integration interface connection as a scriptable object. Parameters that were available for Python Connect() in JMP 14-17 are deprecated.

Python Control()

Description

This function is deprecated.

Python Create JPIP CMD()

Description

Triggers the creation of a jpip command line wrapper script for Python’s pip command. A directory picker dialog will ask for the directory location to save the generated script. This script then provides the full capabilities of pip, while correctly establishing the necessary environment variables for JMP’s isolated Python environment.

Example

Names Default To Here( 1 );
Python Create JPIP CMD();

Python Disconnect()

This function is deprecated.

Python Execute({list of inputs}, {list of outputs}, Python_Code)

Description

Submits Python code to the Python environment given a list of inputs. On completion, returns a list of outputs.

Returns

Returns 0 if successful and 1otherwise.

Positional Arguments

{list of inputs}

A list of JMP variable names to be sent to Python as inputs.

{list of outputs}

A list of JMP variable names to be retrieved from Python as outputs.

Python_Code

The Python code to submit.

Example

This example sends a character variable, a numeric variable, and a set of matrices to Python. Python is then instructed to perform a set of matrix operations on the sent matrices. The Python Execute() function then gets the set of matrices created by the matrix operations and gets the values of the character and numeric variables that was originally sent.

Names Default To Here( 1 );
 
a = "abcdef";
d = 3.141;
x = 0;
z = 0;
v = [1 0 0, 0 1 0, 0 0 1];
// pi, e, phi, c, Plank's, Faraday, 345 triangle
m = [3.141 2.718 1.618,
2.997 6.626 9.648,
3 4 5];
ml = Python Execute(
	{v, m, a, d},
	{x, z, a, d},
	"\[
import numpy as np
a = np.multiply(v, m) # matrix product
d = np.divide(v, m) # matrix division
z = np.multiply(m, np.linalg.inv(v)) # m * inv(v) called Left division
x = np.multiply(np.linalg.inv(m), v) # inv(m) * v called right division
]\"
);
Show( v, m, ml, x, z, a, d );

v =

[ 1 0 0,

0 1 0,

0 0 1];

m =

[ 3.141 2.718 1.618,

2.997 6.626 9.648,

3 4 5];

ml = 0;

x =

[ -0.681183278459541 0 0,

0 1.3532624962586 0,

0 0 1.57966926070039];

z =

[ 3.141 0 0,

0 6.626 0,

0 0 5];

a =

[ 3.141 0 0,

0 6.626 0,

0 0 5];

d =

[ 0.318369945877109 0 0,

0 0.150920615756112 0,

0 0 0.2];

Python Get(name)

Description

Gets a named variable from Python to JMP.

Returns

Returns the value of the named variable.

Argument

name

The name of the Python variable to be sent to JMP. The argument can represent any of the following Python data types: numeric, quoted string, matrix, list, or data frame.

Example

Names Default To Here( 1 );
 
x1 = {1, 2, 3};
Python Send( x1 );
x2 = Python Get( x1 );
Show( x1, x2 );

x1 = {1, 2, 3};

x2 = {1, 2, 3};

Python Get Graphics()

Description

This function is deprecated and will generate a syntax error when used. It returned the last graphics object written by matplotlib’s pyplot in a graphics format specified by the format argument.

Example

The following example shows the previous method commented out and the new alternative.

Names Default To Here( 1 );
 
ml = Python Submit(
	"\[
# This sample requires the matplotlib package to be installed.
import matplotlib.pyplot as plt
plt.clf()         # make sure we are starting with a clean plot
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.draw()
 
# Save image to location of your choosing
plt.savefig('/tmp/get_graphics_img.png')
]\"
);
// plot = Python Get Graphics( png );       // DEPRECATED
plot = Open( "/tmp/get_graphics_img.png", png );
pngJMP = New Window( "Plot", Picture Box( plot ) );
Python Submit( "plt.close()" );
rc = Delete File( "/tmp/get_graphics_img.png" );

Python Get Version()

Description

Returns the version number of Python being used with the JMP Python interfaces.

Python Init()

Description

This function is deprecated and is equivalent to Python Connect().

Example

Names Default To Here( 1 );
 
Python Init();
Python Submit( "\[
str = 'The quick brown fox jumps over the lazy dog';
]\" );
getStr = Python Get( str );
Show( getStr );

getStr = "The quick brown fox jumps over the lazy dog";

Python Install Packages(packages)

Description

This wrappers the install of Python packages into the JMP site-packages directory. For operations beyond simple package installation, use Python Create JPIP CMD() to create a command line wrapper script in a directory chosen with Directory Pick(). Alternatively, to run the install from a JMP Python script window, see Install Python Packages in JMP’s Python Environment in the JMP Scripting Guide.

Example

Names Default To Here( 1 );
// Install numpy and pandas packages
Python Install Packages( "numpy pandas" );

Python Is Connected

This function is deprecated and always returns 1.

Python JMP Name to Python Name(name)

Description

Maps a JMP variable name to its corresponding Python variable name using Python variable name naming rules.

Returns

A quoted string, the mapped Python name.

Argument

name

The name of the JMP variable to be sent to Python.

Python Send(name, <Python Name( name )>)

Description

Sends a named variable from JMP to Python.

Returns

Returns 0 if successful.

Arguments

name

The name of the JMP variable to be sent to Python.

<Python Name( name )>

Specifies the name assigned to the variable in the Python environment.

Python Send File(name, <Python Name( name )>)

Description

Sends a data file to Python. The filename argument is a quoted string that specifies a pathname to the file to be sent to Python.

Argument

name

The name of the file to be sent to Python.

<Python Name( name )>

Specifies the name assigned to the file in the Python environment.

Python Submit(Python_Code)

Description

Submits Python code to the Python environment.

Returns

Returns 0 if successful and non-zero otherwise.

Arguments

Python_Code

The Python code to submit. Statements can be a quoted string value or a list of string values.

Example

Names Default To Here( 1 );
Python Submit( "\[
str = 'The quick brown fox jumps over the lazy dog'
a = 200]\" );
getStr = Python Get( str );
getNum = Python Get( a );
Show( getStr, getNum );

getStr = "The quick brown fox jumps over the lazy dog";

getNum = 200;

Python Submit File(path)

Description

Submits statements to Python using the file specified in the path name.

Argument

path

The path to the file that contains the Python source lines to be executed.

Python Term()

This function is Deprecated.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).