Table of Contents
This MineSight Grail will work with Python 2.7.6 .
The search is done via a set of steps described in Section 6.1.1 of the Python Tutorial for details.
It is a bit complicated, so it might be helpful to explain this via an example. When python parses the line "import grail", it does the following search for a "grail module",
- Starting in the Local Working Directory,
- Is there a grail.pyc (or *.pyo) that is younger than a grail.py?
- Is there a grail.py
- Is there a grail directory that contains an __init__.py or __init__.pyc.
- Is there a grail.pth file (old way of specifying modules).
- For each path specified on PYTHONPATH,
- Is there a grail.pyc (or *.pyo) that is younger than a grail.py?
- Is there a grail.py
- Is there a grail directory that contains an __init__.py or __init__.pyc.
- Is there a grail.pth file (old way of specifying modules).
It then repeats the steps again through the Python system directories.
There is a trick to allow you to see the directory search order that python takes, if you type the following from the command line (assuming python.exe is on your path),
c:\>python -c "import pprint, sys; pprint.pprint(sys.path)"
For example, with PYTHONPATH equal to c:\winexe, I get,
['',
'C:\\WINEXE',
'C:\\Python22\\lib\\site-packages\\Pythonwin',
'C:\\Python22\\lib\\site-packages\\win32',
'C:\\Python22\\lib\\site-packages\\win32\\lib',
'C:\\Python22\\lib\\site-packages',
'c:\\Python22\\DLLs',
'c:\\Python22\\lib',
'c:\\Python22\\lib\\lib-tk',
'C:\\Python22',
'c:\\Python22\\lib\\site-packages\\Numeric',
'c:\\Python22\\lib\\site-packages\\PIL']
Note that in that list, the '' is referring to the local working directory, which in this example, would be the c:/ drive.
If the following python import statement,
import zipfile
is generating the following error,
then you are running into a conflict of "zlibs" (zip compression library) which can be resolved by replaceing import zlib with the following,
This effectively tells the python interpreter to make sure it always looks in the python "DLLs" directory for zlib.pyd before it starts looking elsewhere. You may have a zlib.dll that is "found" before the real zlib.pyd is found.
Sometimes you want to know the name of the directory that contains your script. The following little snippet will help you determine that:
this will show the location of the script directory when you import the script or if you just run the script. See also "Dive Into Python: 16.2 Finding the path" [1] for more details.
Starting in version 4.60, you can also listen for messages from '''gmain'''.
for PY/PYC files the logical and actual script paths will be the same. For a PYZ file the actual script path will be where the script is begin executed from, and the logical script path will be where script was picked.
In earlier versions you would have to listen to the messages sent to gmain, as in,
if your script_path and log_script_path are globals, make sure to use the "global" directive in your function.
There are two ways to do it: one from MS3D and one from the command line.
From MineSight(r) 3D (MS3D):
Run MS3D
Select
Pick the em-info.py script found in the $(medexe)\scripts directory.
This should display information on the MSGRAIL installation and python within the MS3D message window. Including the version number of MSGRAIL library that you are using.
From the Command Line
You can type the following from the command line, assuming that you have grail installed, and python is available on the path,
python -c "import grail.info; print grail.info.DESCRIPTION"
There are two ways to do it: one from MS3D and one from the command line.
From MineSight(r) 3D (MS3D):
Run MS3D
Select
Pick the em-info.py script found in the $(medexe)\scripts directory.
This should display information on the MSGRAIL installation and python within the MS3D message window. Including the location of the MSGRAIL library that you are using.
From the Command Line
You can type the following from the command line, assuming that you have grail installed, and python is available on the path,
python -c "import grail.info; print grail.info.DESCRIPTION"
See the HowTo for Determining Available Files for the Current Compass Project. If you want to find all files, regardless of availablity, see the next question.
[1] | "16.2 Finding the path". Dive Into Python: Python from novice to pro. 28 June 2007. <http://www.diveintopython.org/functional_programming/finding_the_path.html> |