HowTo: Create a PYZ

Version: 16.2

Table of Contents

New in version 4.60.

Preface

The PYZ format provides the ability to package a set of scripts together as one file, and execute that set of scripts as one entity.

This document outlines the process of creating a script.

Assumptions

It is assumed that you are familiar with the MineSight® 3D, and the basic mechanics of a python script.

You will require MineSight® 3D version 4.60 to run a PYZ file. You will also require MPYTHON version 1.1 to use the "mpython" command on a PYZ file from the command line. If you do not have MPYTHON 1.1, you can use the mspz.exe to launch a PYZ from the command line.

Getting Started

To create a PYZ all you need is a zip utility program. In our examples we are using the zip.exe that is available from UnxUtils.

The layout of a PYZ is simple. You need to follow these rules,

  1. The PYZ must have a root file with the same name. If your pyz is called "run-code.pyz", then your root file must be called "run-code.py".
  1. Your root file must have a gmain, and that gmain must follow the rules of a standard MineSight® script.

As an example, lets convert the file %MEDEXE%/scripts/samples/pyz-boilerplate.py into a PYZ file. First we will rename the file to sample.py.

copy %MEDEXE%/scripts/samples/pyz-boilerplate.py sample.py

next we will build the PYZ file using zip.exe as follows,

zip.exe sample.pyz sample.py

now we have a PYZ file that can be executed in MS3D, MSCOMPASS, or via the command line using mspz.exe (note, MPYTHON 1.1 automatically forwards to mspz.exe).

If you want to package a single PYZ out of a set of files, you would repeat the above example with something like,

zip.exe sample.pyz sample.py some_lib.py other_lib.py

and now, your root file, sample.py, will be executed, and the some_lib.py and other_lib.py will be available to the script. In other words, if your script had,

import some_lib
import other_lib

it would import the files that you put into your PYZ package.

Boilerplate

The %MEDEXE%/scripts/samples/pyz-boilerplate.py will always show the most up-to-date method of creating a good root file for your PYZ package.