========================== Frequently Asked Questions ========================== .. include:: version.h .. contents:: Table of Contents :backlinks: top ------------------------------ 1.0 MineSight Grail and Python ------------------------------ 1.1 Q: What Version of Python Can We Use with MineSight Grail? -------------------------------------------------------------- This MineSight Grail will work with Python @PYTHON_VER@. 1.2 Q: How does Python search for MSGRAIL? ------------------------------------------ The search is done via a set of steps described in `Section 6.1.1 of the Python Tutorial`__ for details. __ http://docs.python.org/tut/node8.html#SECTION008110000000000000000 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, 1. Is there a :file:`grail.pyc` (or \*.pyo) that is younger than a :file:`grail.py`? 2. Is there a :file:`grail.py` 3. Is there a grail directory that contains an :file:`__init__.py` or :file:`__init__.pyc`. 4. Is there a grail.pth file (old way of specifying modules). - For each path specified on PYTHONPATH, 1. Is there a :file:`grail.pyc` (or \*.pyo) that is younger than a :file:`grail.py`? 2. Is there a :file:`grail.py` 3. Is there a grail directory that contains an :file:`__init__.py` or :file:`__init__.pyc`. 4. Is there a :file:`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 :file:`c:\\winexe`, I get, .. Python:: ['', '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 :file:`c:/` drive. 1.3. Q: I am unable to import zipfile, what can I do? ----------------------------------------------------- If the following python import statement, .. Python:: import zipfile is generating the following error, .. Python:: ImportError: dynamic module does not define init function (initzlib) then you are running into a conflict of "zlibs" (zip compression library) which can be resolved by replaceing ``import zlib`` with the following, .. Python:: # Workaround to load the zlib module, which ends up conflicting with # our MEDEXE directory. import os, sys sys.path.insert(0, os.path.join(sys.prefix, "DLLs") ) import zlib import zipfile This effectively tells the python interpreter to make sure it always looks in the python "DLLs" directory for :file:`zlib.pyd` before it starts looking elsewhere. You may have a :file:`zlib.dll` that is "found" before the real :file:`zlib.pyd` is found. ------------------------------ 2.0 Common Scripting Questions ------------------------------ 2.1 Q: How can I determine the Script's Directory? -------------------------------------------------- Sometimes you want to know the name of the directory that contains your script. The following little snippet will help you determine that: .. Python:: # Defines the location of the script directory. import os import sys if __name__=="__main__": SCRIPT_DIR = os.path.dirname(sys.argv[0]) else: SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 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" [#dive-into-find-path]_ for more details. Starting in version 4.60, you can also listen for messages from '''gmain'''. .. Python:: def main(): # The TRUE script path, may be unpacked elsewhere. print gmain.actual_path # The location a user selected the data from. print gmain.logical_path gmain = gsys.GMAIN(main, __name__) gmain.run() 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 :f:`gmain`, as in, .. Python:: def gmain(m,d): global script_path global log_script_path if m == messages.gACTUAL_SCRIPT_PATH: # The TRUE script path, may be unpacked elsewhere. script_path = d elif m == message.gLOGICAL_SCRIPT_PATH: # The location a user selected the data from. log_script_path = d if your :d:`script_path` and :d:`log_script_path` are globals, make sure to use the "global" directive in your function. 2.2 Q: How can I quickly swap y,z coordinates within a point list? ------------------------------------------------------------------ See `Efficiently Swapping Y and Z Coordinates`_ in the HowTo_. .. _Efficiently Swapping Y and Z Coordinates: HowTo/howto-efficiently-swap-yz.html .. _HowTo: HowTo/index.html -------------------- 3.0 Trouble Shooting -------------------- 3.1 Q: How can I determine what version of MSGRAIL I am using? -------------------------------------------------------------- There are two ways to do it: one from MS3D and one from the command line. - From MineSight(r) 3D (MS3D): 1. Run MS3D 2. Select :menu:`File->Scripts->Run Script...` 3. Pick the :file:`em-info.py` script found in the :file:`$(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 1. 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" 3.2 Q: How can I determine the location of my MSGRAIL installation? ------------------------------------------------------------------- There are two ways to do it: one from MS3D and one from the command line. - From MineSight(r) 3D (MS3D): 1. Run MS3D 2. Select :menu:`File->Scripts->Run Script...` 3. Pick the :file:`em-info.py` script found in the :file:`$(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 1. 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" ------------------------------- 4.0 MineSight Grail and Compass ------------------------------- 4.1 Q: How can I determine the available files in a Compass Project? -------------------------------------------------------------------- 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. 4.2 Q: How can I determine the files in a Compass Project? ---------------------------------------------------------- See the `HowTo`_ for `Determining Available Files for the Current Compass Project`_. .. _Determining Available Files for the Current Compass Project: HowTo/howto-compass-detavail-files-current-proj.html ---------- References ---------- .. [#dive-into-find-path] "16.2 Finding the path". *Dive Into Python: Python from novice to pro*. 28 June 2007.