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.11.0.
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.1.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.
- Select the menu Connectivity:Python Console....
- Copy and paste one line at a time from below, and press Enter to execute:
import originpro as op
To reset the Origin Python environment:
- Choose Window: Script Window and run the following command:
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.
- From the Origin menu, choose Connectivity: Open untitled.py...
- In the tab named untitiled.py on the right side, enter the following line of code:
print ("Hello World!")
- Select the File: Save As... menu and type Hello in the File Name edit box and save the file.
- Go back to Origin and select the menu Window: Script Window.
- 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: