Python Installation and Configuration
Configure Python from Geosoft Desktop (Oasis montaj)
A Python menu (Python.omn) is available for use with Geosoft Desktop. The Python menu has an option to run a Python extension script and a set of configuration GXs that support installation and verification from a running Geosoft Desktop application. To install and use the Python menu:
- Download python_desktop_setup.gx and run this GX from an open Geosoft desktop application. This will install menu
Python.omn
to youruser\omn
folder, the supporting GXs to youruser\gx
folder and thehello_world.py
file to your .../user/python folder. - Load the
Python
menu from the User Menus section of Menu Manager:
The Python menu has the following configuration options:
Configure Python... | Description |
---|---|
Install Python | Instructions for installing Python from Anaconda. |
Locate Python... | Locate the Python folder, from which Geosoft will run Python. A restart is required if you change the Python folder. |
Verify Python | Verifies your Python installation and reports any problems. The Python and Geosoft API version numbers are reported if successful: |
Hello World | Run the simple .../user/python/hello_world.py script, which will display a "Hello" dialog: See Hello World#DesktopExtension, which describes how this simple extension works. |
Update Geosoft Package | Use this to update the Geosoft Python package as updates become available. A restart is required after an update. Note: Running this behind certain firewalls will require the user to configure the PIP_CERT environment with a valid certificate. |
Re-start Desktop | Instructions to restart your desktop application. |
If successful the Verify Python step will report the verified installation with the expected Python version number and Geosoft API version. If this is the case then your installation is good and you can skip the remainder of this page. The remaining sections on this page explain the different parts of the installation process in more detail, which can be useful should you be working with a non-standard environment.
64-bit Python 3
Geosoft GX Developer for Python requires 64-bit Python 3.5 or 3.6 be available on systems that use Python. If you are a Python developer you should already have Python installed, or you will be comfortable installing or updating to the correct version. This section provides only basic information for installing and preparing a system to run Python.
You may find that Python is already installed in more than one location on your system as some programs will install their own version to ensure a stable environment for their own use. For example, ArcGIS Pro installs Python 3 here:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
If you already have ArcGIS Pro installed, or some other version of Python 3.5 or 3.6 installed you may choose to use that installation, in which case you only need to install the Geosoft modules as explained in the next section. You should be careful adding to or changing the configuration of Python installed for other purposes (like ArcGIS) as those systems have specific needs and modifying their environment may cause problems. Geosoft has verified the Geosoft modules against the ArcGIS Pro 64-bit Python 3.5 installation, which means you can install Geosoft into ArcGIS Pro and Python scripts that run inside ArcGIS Pro can access the Geosoft API.
If you do not already have Python 3.5 or later we recommend that you install the Anaconda version of Python:
- Go to the Anaconda web site and download Anaconda for Windows. Choose the latest version 64-bit installer for Python 3 (at time of writing, Anaconda 5.0.1, Python 3.6 version, 64-bit installer).
- Launch the installer and follow the instructions. We suggest you install Python for all users of your computer. Note the installation folder name. In this guide we assume Python has been installed in folder
C:\ProgramData\Anaconda3
. Open a command prompt and verify your Python version:
Python versions
Because a system can have multiple versions of Python it is important that you are running the correct Python interpreter (python.exe). The folder in which the python.exe file is located establishes the Python version and environment in use. We recommend that you always explicit define the python.exe file you intend to use by including the complete path (in this example C:\ProgramData\Anaconda3\python.exe).
Geosoft modules must, of course, be installed in the Python environments that depends on the Geosoft modules. The next section explains how to install Geosoft Python modules.
Install Geosoft Python Modules
Geosoft maintains the GX Developer Python modules in the globally accessible Python Package Index on PyPI, which allows for convenient installation using pip. The pip.exe program is located in the Scripts sub-directory of the Python environment you will be using.
Install to a standard Anaconda installation (versions and details will be as per the installation installed):
Install to an ArcGIS Pro installation:
Should you need to install the Geosoft modules to match an installed Geosoft Desktop Platform installation you can specify the version as follows. You only need to define the major.minor version number (9.2 in the example) and the most recent module version for that platform will be installed. It is a good idea to first remove an existing version:
c:\ProgramData\Anaconda3\scripts\pip uninstall geosoft ... c:\ProgramData\Anaconda3\scripts\pip install geosoft==9.2 ... C:\ProgramData\Anaconda3\scripts\pip show geosoft Name: geosoft Version: 9.2.1 Summary: Geosoft GX API module for Python Home-page: https://github.com/GeosoftInc/gxpy Author: Geosoft Inc. Author-email: support@geosoft.com License: BSD Location: c:\programdata\anaconda3\lib\site-packages Requires: xmltodict, pandas, numpy
Test your configuration
We will now run Python to verify the python installation. You must run the python.exe file from the Python installation for which you installed the Geosoft modules. For example, if you installed to the ArcGIS Pro Python, run from:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe.
In this example we assume a standard Anaconda3 installation:
C:\ProgramData\Anaconda3>python Python 3.6.2 |Anaconda, Inc.| (default, Sep 19 2017, 08:03:39) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import geosoft.gxpy >>> gx_context = geosoft.gxpy.gx.GXpy() >>> gx_context.gid 'you@your_organization' >>> exit() C:\Anaconda3>
line 4 | import the geosoft.gxpy module. If this fails it means Geosoft is not properly installed in the Python 3 environment for this python.exe.
C:\ProgramData\Anaconda3\scripts\pip show geosoft Name: geosoft Version: 9.3.0 Summary: Geosoft GX API module for Python Home-page: https://github.com/GeosoftInc/gxpy Author: Geosoft Inc. Author-email: support@geosoft.com License: BSD Location: c:\programdata\anaconda3\lib\site-packages Requires: xmltodict, pandas, numpy |
---|---|
line 5 | The first thing Python scripts must to do is create and hold a GX context. Line 5 creates this context, which will use Geosoft Connect to validate your Seequent ID. |
line 6 | One of the properties of the GX context is the Seequent ID of the person running the script. Line 6 writes this property to the console. You should see your Seequent ID. |
Configuring Geosoft Desktop to Run Python Extensions
Geosoft Desktop can also run Python scripts as extensions that work within the context of a running Geosoft Desktop application (Oasis montaj, Target or the Viewer). Before running a Python extension, Desktop needs to be configured to identify the location of your Python interpreter. To do this, open Oasis montaj and select Settings → Global Settings → Python:
Browse to the folder that contains the python.exe interpreter.
Show console: The Python console is a console window that will display text output to stdout (Python print statements) and stderr (Python error messages) and accept input from stdin (Python input statements). For known stable extensions that do not require a console, you may choose to hide the console which makes for a cleaner user experience.