1 Embedded Python

Running Python Inside Origin

When you install Origin, Python is also installed. This installation is referred to as Embedded Python, and is independent of any Python versions you may have installed outside of Origin. The current version of Embedded Python is 3.8.3.

An originpro package is also pre-installed for immediate use from the Embedded Python, to interact with Origin object such as worksheets, matrixsheets and graphs. The current version of originpro package is 1.0.6.

There are several ways to access Python code from within Origin. The following two sections provide quick examples.

Run Python Command in Console

You can execute Python commands in the Python Console in Origin. This is useful if you are executing just a few lines of code.

  1. Select the menu Connectivity:Python Console....
  2. Copy and paste one line at a time from below, and press Enter to execute:
import originpro as op
wks=op.new_sheet()
f=op.path('e')+r'Samples\Curve Fitting\Enzyme.dat'
wks.from_file(f)

Beginning with Origin 2021b, Intellisense (auto-completion) is enabled by default. You can disable Intellisense by setting system variable @NPYC = 0. For information on changing the value of a LabTalk system variable see FAQ-708 How do I permanently change the value of a system variable?

Hello World Example

Python code can be stored and accessed from several places such as external files, files attached to the Origin project, included in Set Column Values dialog, or stored in text objects in a graph or worksheet window.

In this simple example, we will save our Python code to a .py file and execute it from Origin's Script Window.

  1. From the Origin menu, choose Connectivity: Open untitled.py...
  2. In the tab named untitiled.py on the right side, enter the following line of code:
    print ("Hello World!")
  3. Select the File: Save As... menu and type Hello in the File Name edit box and save the file.
  4. Go back to Origin and select the menu Window: Script Window.
  5. Type the following command in the Script Window and press Enter to execute:
    run -pyf "Hello.py"

The message "Hello World!" is returned to the Script Window (see run -pyf).

Where to go from here?

To learn more about how to use Embedded Python in Origin, please review the following pages: