2 Installing and Managing Python Packages
Once you start working with embedded Python in Origin, you will sooner or later need to install specific Python packages such as numpy, scipy etc.
You have two options for installing and managing packages, and these are outlined in the following sections.
NOTE: It is good practice to restart Origin after installing packages. This can resolve any issues such as lack of immediate access to the package after installation.
For those without an internet connection and/or who have a WHL file on the file system, see Installing Wheel Files below.
Using the Python Packages Tool
A GUI tool named Python Packages is available for installing and managing packages. This tool is accessible from the Origin menu: Connectivity: Python Packages... and also from the Code Builder menu: Tools: Python Packages....
The tool provides options to install, upgrade and uninstall packages. The Pause output window check box allows to keep the Command window open to monitor progress.
Using LabTalk Script
Python packages can be installed and managed from LabTalk script using the pip command. The easiest way is to run the command from the Script Window (Window: Script Window).
- Note that when executing a single line of script in the Script Window, you do not include the semi-colon (;) at the end of the line.
- To execute multiple lines of script, make sure all (except comments) have a terminating semi-colon (;), highlight all lines to be executed, then press Enter.
// Install pandas package:
pip install pandas;
All dependent packages for pandas will be automatically installed, such as NumPy, six, python-dateutil, and pytz.
Use the -chk option to check if package is already installed and is up to date.
pip -chk pandas; // Asks for permission to install, otherwise reports already installed
pip -chk1 pandas; // Shows message if not installed, otherwise does nothing
Multiple package names can be specified in the command:
pip -chk scipy pandas; // Dialog will show only those packages that are not yet installed
Packages can be uninstalled from script. Note that there is no confirmation dialog.
pip uninstall pandas;
pip uninstall *; // Uninstall all packages
You can also check for installed packages using the Python Object in LabTalk:
This method will return:
- 0: All packages are available
- 1: Installation is needed and was initiated
- 2. Embedded Python not installed
- 3. No internet connection or user refused to install
This method is useful to check for packages when creating Apps that utilize Python script. To learn more, please review App Development using Python.
Installing Wheel Files
For those without an internet connection and/or who have a WHL file on the file system, please follow these steps to install the file:
- In Origin, open the Command Window from the main Window menu.
- Type in the following command, replacing the path to the WHL file and enclosing the path in double quotes:
pip install "C:\Path\To\Wheels\anywheel.whl";