Main Page Basics, Building SPICE Applications (Python)
## Table of Contents
       Basics, Building SPICE Applications (Python)
          Note About HTML Links
          Environment Set-up
          Confirm that Python can access SpiceyPy
          A simple example program
          SpiceyPy Documentation
Top # Basics, Building SPICE Applications (Python) May 21, 2018 Top ## Note About HTML Links The HTML version of this lesson contains links pointing to various HTML documents provided with the Toolkit. All of these links are relative and, in order to function, require this document to be in a certain location in the Toolkit HTML documentation directory tree. In order for the links to be resolved, if not done already by installing the lessons package under the Toolkit's ``doc/html'' directory, create a subdirectory called ``lessons'' under the ``doc/html'' directory of the ``cspice/'' tree and copy this document to that subdirectory before loading it into a Web browser. Top ## Environment Set-up SpiceyPy is currently supported on Mac, Linux, and Windows systems. In order to install SpiceyPy, using pip, first install the following required packages:
                  $ pip install six
                  $ pip install numpy
                  $ pip install spiceypy
Python2 users would need to use the future package in order to get the same behavior from the Python3 input function in Python2. This package is installed by running:
                  $ pip install future
Using anaconda, miniconda or conda:
          $ conda install -c https://conda.anaconda.org/andrewannex spiceypy
Top ## Confirm that Python can access SpiceyPy Run pip list in order to get a list of the third party libraries that are currently available to your Python installation:
          $ pip list --format=columns
          Package    Version
          ---------- -------
          pip        9.0.1
          numpy      1.13.3
          setuptools 36.5.0
          six        1.11.0
          ...
          spicepy    2.1.1
          ...
Top ## A simple example program This script calls the spiceypy function 'tkvrsn' and outputs the return value.
               File tkvrsn.py

                  from __future__ import print_function
                  import spiceypy

                  def print_ver():
                          """Prints the TOOLKIT version
                          """
                          print(spiceypy.tkvrsn('TOOLKIT'))

                  if __name__ == '__main__':
                          print_ver()
From the command line, execute the function:
               $ python tkvrsn.py
               CSPICE_N0066
From Python, execute the function:
               $ python
               >>> import tkvrsn
               >>> tkvrsn.print_ver()
               CSPICE_N0066
Top ## SpiceyPy Documentation The current version of SpiceyPy does not provide extensive documentation, but there are several ways to navigate your way through the Python version of the toolkit. One simple way is to use the standard Python mechanisms. All interfaces implemented in SpiceyPy can be listed using the standard built-in function dir(), which returns an alphabetized list of names comprising (among) other things, the API names. If you need to get additional information about an API parameters, the standard built-in function help() could be used:
       >>> import spiceypy
       >>> help(spiceypy.)
which produces
       Help on function tkvrsn in module spiceypy.spiceypy:

       tkvrsn(item)
           Given an item such as the Toolkit or an entry point name, return
           the latest version string.

           http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/tkvrsn_c.
       html

           :param item: Item for which a version string is desired.
           :type item: str
           :return: the latest version string.
           :rtype: str
As indicated in the help on the function, the complete documentation is available on the CSPICE toolkit version. Therefore it is recommended to have the CSPICE toolkit version installed locally in order to access its documentation offline.