CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/cwd/usr/share/doc/python-docs-2.6.6/html/using/
Upload File :
Current File : //proc/2/cwd/usr/share/doc/python-docs-2.6.6/html/using/mac.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>4. Using Python on a Macintosh &mdash; Python v2.6.6 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.6',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.6 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.6 documentation" href="../index.html" />
    <link rel="up" title="Using Python" href="index.html" />
    <link rel="next" title="The Python Language Reference" href="../reference/index.html" />
    <link rel="prev" title="3. Using Python on Windows" href="windows.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="../reference/index.html" title="The Python Language Reference"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="windows.html" title="3. Using Python on Windows"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.6 documentation</a> &raquo;</li>

          <li><a href="index.html" accesskey="U">Using Python</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="using-python-on-a-macintosh">
<span id="using-on-mac"></span><h1>4. Using Python on a Macintosh<a class="headerlink" href="#using-python-on-a-macintosh" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Bob Savage &lt;<a class="reference external" href="mailto:bobsavage&#37;&#52;&#48;mac&#46;com">bobsavage<span>&#64;</span>mac<span>&#46;</span>com</a>&gt;</td>
</tr>
</tbody>
</table>
<p>Python on a Macintosh running Mac OS X is in principle very similar to Python on
any other Unix platform, but there are a number of additional features such as
the IDE and the Package Manager that are worth pointing out.</p>
<p>The Mac-specific modules are documented in <a class="reference external" href="../library/mac.html#mac-specific-services"><em>Mac OS X specific services</em></a>.</p>
<p>Python on Mac OS 9 or earlier can be quite different from Python on Unix or
Windows, but is beyond the scope of this manual, as that platform is no longer
supported, starting with Python 2.4. See <a class="reference external" href="http://www.cwi.nl/~jack/macpython">http://www.cwi.nl/~jack/macpython</a> for
installers for the latest 2.3 release for Mac OS 9 and related documentation.</p>
<div class="section" id="getting-and-installing-macpython">
<span id="getting-osx"></span><h2>4.1. Getting and Installing MacPython<a class="headerlink" href="#getting-and-installing-macpython" title="Permalink to this headline">¶</a></h2>
<p>Mac OS X 10.5 comes with Python 2.5.1 pre-installed by Apple.  If you wish, you
are invited to install the most recent version of Python from the Python website
(<a class="reference external" href="http://www.python.org">http://www.python.org</a>).  A current &#8220;universal binary&#8221; build of Python, which
runs natively on the Mac&#8217;s new Intel and legacy PPC CPU&#8217;s, is available there.</p>
<p>What you get after installing is a number of things:</p>
<ul class="simple">
<li>A <tt class="docutils literal"><span class="pre">MacPython</span> <span class="pre">2.5</span></tt> folder in your <tt class="docutils literal"><span class="pre">Applications</span></tt> folder. In here
you find IDLE, the development environment that is a standard part of official
Python distributions; PythonLauncher, which handles double-clicking Python
scripts from the Finder; and the &#8220;Build Applet&#8221; tool, which allows you to
package Python scripts as standalone applications on your system.</li>
<li>A framework <tt class="docutils literal"><span class="pre">/Library/Frameworks/Python.framework</span></tt>, which includes the
Python executable and libraries. The installer adds this location to your shell
path. To uninstall MacPython, you can simply remove these three things. A
symlink to the Python executable is placed in /usr/local/bin/.</li>
</ul>
<p>The Apple-provided build of Python is installed in
<tt class="docutils literal"><span class="pre">/System/Library/Frameworks/Python.framework</span></tt> and <tt class="docutils literal"><span class="pre">/usr/bin/python</span></tt>,
respectively. You should never modify or delete these, as they are
Apple-controlled and are used by Apple- or third-party software.  Remember that
if you choose to install a newer Python version from python.org, you will have
two different but functional Python installations on your computer, so it will
be important that your paths and usages are consistent with what you want to do.</p>
<p>IDLE includes a help menu that allows you to access Python documentation. If you
are completely new to Python you should start reading the tutorial introduction
in that document.</p>
<p>If you are familiar with Python on other Unix platforms you should read the
section on running Python scripts from the Unix shell.</p>
<div class="section" id="how-to-run-a-python-script">
<h3>4.1.1. How to run a Python script<a class="headerlink" href="#how-to-run-a-python-script" title="Permalink to this headline">¶</a></h3>
<p>Your best way to get started with Python on Mac OS X is through the IDLE
integrated development environment, see section <a class="reference internal" href="#ide"><em>The IDE</em></a> and use the Help menu
when the IDE is running.</p>
<p>If you want to run Python scripts from the Terminal window command line or from
the Finder you first need an editor to create your script. Mac OS X comes with a
number of standard Unix command line editors, <strong>vim</strong> and
<strong>emacs</strong> among them. If you want a more Mac-like editor,
<strong>BBEdit</strong> or <strong>TextWrangler</strong> from Bare Bones Software (see
<a class="reference external" href="http://www.barebones.com/products/bbedit/index.shtml">http://www.barebones.com/products/bbedit/index.shtml</a>) are good choices, as is
<strong>TextMate</strong> (see <a class="reference external" href="http://macromates.com/">http://macromates.com/</a>). Other editors include
<strong>Gvim</strong> (<a class="reference external" href="http://macvim.org">http://macvim.org</a>) and <strong>Aquamacs</strong>
(<a class="reference external" href="http://aquamacs.org/">http://aquamacs.org/</a>).</p>
<p>To run your script from the Terminal window you must make sure that
<tt class="docutils literal"><span class="pre">/usr/local/bin</span></tt> is in your shell search path.</p>
<p>To run your script from the Finder you have two options:</p>
<ul class="simple">
<li>Drag it to <strong>PythonLauncher</strong></li>
<li>Select <strong>PythonLauncher</strong> as the default application to open your
script (or any .py script) through the finder Info window and double-click it.
<strong>PythonLauncher</strong> has various preferences to control how your script is
launched. Option-dragging allows you to change these for one invocation, or use
its Preferences menu to change things globally.</li>
</ul>
</div>
<div class="section" id="running-scripts-with-a-gui">
<span id="osx-gui-scripts"></span><h3>4.1.2. Running scripts with a GUI<a class="headerlink" href="#running-scripts-with-a-gui" title="Permalink to this headline">¶</a></h3>
<p>With older versions of Python, there is one Mac OS X quirk that you need to be
aware of: programs that talk to the Aqua window manager (in other words,
anything that has a GUI) need to be run in a special way. Use <strong>pythonw</strong>
instead of <strong>python</strong> to start such scripts.</p>
<p>With Python 2.5, you can use either <strong>python</strong> or <strong>pythonw</strong>.</p>
</div>
<div class="section" id="configuration">
<h3>4.1.3. Configuration<a class="headerlink" href="#configuration" title="Permalink to this headline">¶</a></h3>
<p>Python on OS X honors all standard Unix environment variables such as
<span class="target" id="index-1132"></span><a class="reference external" href="cmdline.html#envvar-PYTHONPATH"><strong class="xref">PYTHONPATH</strong></a>, but setting these variables for programs started from the
Finder is non-standard as the Finder does not read your <tt class="docutils literal"><span class="pre">.profile</span></tt> or
<tt class="docutils literal"><span class="pre">.cshrc</span></tt> at startup. You need to create a file <tt class="docutils literal"><span class="pre">~</span>
<span class="pre">/.MacOSX/environment.plist</span></tt>. See Apple&#8217;s Technical Document QA1067 for details.</p>
<p>For more information on installation Python packages in MacPython, see section
<a class="reference internal" href="#mac-package-manager"><em>Installing Additional Python Packages</em></a>.</p>
</div>
</div>
<div class="section" id="the-ide">
<span id="ide"></span><h2>4.2. The IDE<a class="headerlink" href="#the-ide" title="Permalink to this headline">¶</a></h2>
<p>MacPython ships with the standard IDLE development environment. A good
introduction to using IDLE can be found at <a class="reference external" href="http://hkn.eecs.berkeley.edu/">http://hkn.eecs.berkeley.edu/</a>
dyoo/python/idle_intro/index.html.</p>
</div>
<div class="section" id="installing-additional-python-packages">
<span id="mac-package-manager"></span><h2>4.3. Installing Additional Python Packages<a class="headerlink" href="#installing-additional-python-packages" title="Permalink to this headline">¶</a></h2>
<p>There are several methods to install additional Python packages:</p>
<ul class="simple">
<li><a class="reference external" href="http://pythonmac.org/packages/">http://pythonmac.org/packages/</a> contains selected compiled packages for Python
2.5, 2.4, and 2.3.</li>
<li>Packages can be installed via the standard Python distutils mode (<tt class="docutils literal"><span class="pre">python</span>
<span class="pre">setup.py</span> <span class="pre">install</span></tt>).</li>
<li>Many packages can also be installed via the <strong>setuptools</strong> extension.</li>
</ul>
</div>
<div class="section" id="gui-programming-on-the-mac">
<h2>4.4. GUI Programming on the Mac<a class="headerlink" href="#gui-programming-on-the-mac" title="Permalink to this headline">¶</a></h2>
<p>There are several options for building GUI applications on the Mac with Python.</p>
<p><em>PyObjC</em> is a Python binding to Apple&#8217;s Objective-C/Cocoa framework, which is
the foundation of most modern Mac development. Information on PyObjC is
available from <a class="reference external" href="http://pyobjc.sourceforge.net">http://pyobjc.sourceforge.net</a>.</p>
<p>The standard Python GUI toolkit is <a title="Interface to Tcl/Tk for graphical user interfaces" class="reference external" href="../library/tkinter.html#module-Tkinter"><tt class="xref docutils literal"><span class="pre">Tkinter</span></tt></a>, based on the cross-platform
Tk toolkit (<a class="reference external" href="http://www.tcl.tk">http://www.tcl.tk</a>). An Aqua-native version of Tk is bundled with OS
X by Apple, and the latest version can be downloaded and installed from
<a class="reference external" href="http://www.activestate.com">http://www.activestate.com</a>; it can also be built from source.</p>
<p><em>wxPython</em> is another popular cross-platform GUI toolkit that runs natively on
Mac OS X. Packages and documentation are available from <a class="reference external" href="http://www.wxpython.org">http://www.wxpython.org</a>.</p>
<p><em>PyQt</em> is another popular cross-platform GUI toolkit that runs natively on Mac
OS X. More information can be found at
<a class="reference external" href="http://www.riverbankcomputing.co.uk/software/pyqt/intro">http://www.riverbankcomputing.co.uk/software/pyqt/intro</a>.</p>
</div>
<div class="section" id="distributing-python-applications-on-the-mac">
<h2>4.5. Distributing Python Applications on the Mac<a class="headerlink" href="#distributing-python-applications-on-the-mac" title="Permalink to this headline">¶</a></h2>
<p>The &#8220;Build Applet&#8221; tool that is placed in the MacPython 2.5 folder is fine for
packaging small Python scripts on your own machine to run as a standard Mac
application. This tool, however, is not robust enough to distribute Python
applications to other users.</p>
<p>The standard tool for deploying standalone Python applications on the Mac is
<strong>py2app</strong>. More information on installing and using py2app can be found
at <a class="reference external" href="http://undefined.org/python/#py2app">http://undefined.org/python/#py2app</a>.</p>
</div>
<div class="section" id="application-scripting">
<h2>4.6. Application Scripting<a class="headerlink" href="#application-scripting" title="Permalink to this headline">¶</a></h2>
<p>Python can also be used to script other Mac applications via Apple&#8217;s Open
Scripting Architecture (OSA); see <a class="reference external" href="http://appscript.sourceforge.net">http://appscript.sourceforge.net</a>. Appscript is
a high-level, user-friendly Apple event bridge that allows you to control
scriptable Mac OS X applications using ordinary Python scripts. Appscript makes
Python a serious alternative to Apple&#8217;s own <em>AppleScript</em> language for
automating your Mac. A related package, <em>PyOSA</em>, is an OSA language component
for the Python scripting language, allowing Python code to be executed by any
OSA-enabled application (Script Editor, Mail, iTunes, etc.). PyOSA makes Python
a full peer to AppleScript.</p>
</div>
<div class="section" id="other-resources">
<h2>4.7. Other Resources<a class="headerlink" href="#other-resources" title="Permalink to this headline">¶</a></h2>
<p>The MacPython mailing list is an excellent support resource for Python users and
developers on the Mac:</p>
<p><a class="reference external" href="http://www.python.org/community/sigs/current/pythonmac-sig/">http://www.python.org/community/sigs/current/pythonmac-sig/</a></p>
<p>Another useful resource is the MacPython wiki:</p>
<p><a class="reference external" href="http://wiki.python.org/moin/MacPython">http://wiki.python.org/moin/MacPython</a></p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../contents.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="#">4. Using Python on a Macintosh</a><ul>
<li><a class="reference external" href="#getting-and-installing-macpython">4.1. Getting and Installing MacPython</a><ul>
<li><a class="reference external" href="#how-to-run-a-python-script">4.1.1. How to run a Python script</a></li>
<li><a class="reference external" href="#running-scripts-with-a-gui">4.1.2. Running scripts with a GUI</a></li>
<li><a class="reference external" href="#configuration">4.1.3. Configuration</a></li>
</ul>
</li>
<li><a class="reference external" href="#the-ide">4.2. The IDE</a></li>
<li><a class="reference external" href="#installing-additional-python-packages">4.3. Installing Additional Python Packages</a></li>
<li><a class="reference external" href="#gui-programming-on-the-mac">4.4. GUI Programming on the Mac</a></li>
<li><a class="reference external" href="#distributing-python-applications-on-the-mac">4.5. Distributing Python Applications on the Mac</a></li>
<li><a class="reference external" href="#application-scripting">4.6. Application Scripting</a></li>
<li><a class="reference external" href="#other-resources">4.7. Other Resources</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="windows.html"
                                  title="previous chapter">3. Using Python on Windows</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="../reference/index.html"
                                  title="next chapter">The Python Language Reference</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/using/mac.txt"
         rel="nofollow">Show Source</a></li>
</ul>

          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../reference/index.html" title="The Python Language Reference"
             >next</a> |</li>
        <li class="right" >
          <a href="windows.html" title="3. Using Python on Windows"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.6 documentation</a> &raquo;</li>

          <li><a href="index.html" >Using Python</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Jul 20, 2011.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.6.
    </div>

  </body>
</html>

Copyright 2K16 - 2K18 Indonesian Hacker Rulez