Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>TextMate uses the value of the <code>TM_PYTHON</code> variable to find the path to the Python interpreter. A good solution is to take advantage of TextMate's ability to define variables like <code>TM_PYTHON</code> on a per-project basis:</p> <ol> <li><p>Open a new or existing TextMate Project (<code>File -&gt; New Project</code> or <code>File -&gt; Open</code>)</p></li> <li><p>De-select any file in the project list sidebar.</p></li> <li><p>Click on the <code>Get Info</code> (<strong>i</strong>) icon in the sidebar. A <code>Project Information</code> pane appears.</p></li> <li><p>Click + to add a new variable.</p></li> <li><p>Enter TM_PYTHON in the Variable field and the full path to the desired python in the Value field (for example, <code>/usr/local/bin/python3.1</code>).</p></li> <li><p>Close the Information window and save the Project (<code>File</code> -> <code>Save Project As</code>).</p></li> </ol> <p>Then you can add files as needed to the project and they will be run under the chosen python with TextMate Python bundle's Run Script command. You might want to save a <code>Python 3</code> project, say, for running ad-hoc scripts under Python 3. For bigger projects, you'll want to create a separate TextMate project for it anyway.</p> <p>To change the Python version used globally within <code>TextMate</code>:</p> <ol> <li><p>From the <code>TextMate</code> menu bar, open <code>TextMate</code> -> <code>Preferences</code></p></li> <li><p>click on the <code>Advanced</code> pane</p></li> <li><p>click on the <code>Shell Variable</code> tab</p></li> <li><p>click the <code>+</code> to add a new variable</p></li> <li><p>enter <code>TM_PYTHON</code> in the <code>Variable</code> field and the full path to the python in the <code>Value</code> field (perhaps <code>/usr/local/bin/python3.1</code>)</p></li> </ol> <p>As Alex points out, you may break other TextMate functionality by changing the Python version globally so the per-project change is probably a better solution.</p> <p>UPDATE (2010-10-31):</p> <p>There is another approach that may be easier to use for some projects. The <code>Run</code> command in <code>TextMate</code>'s Python bundle appears to respect a <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)" rel="noreferrer">shebang</a> line in the file being run. So, instead of modifying <code>TM_PYTHON</code>, you can specify the path to the interpreter to be used by including a first line like this:</p> <pre><code>#!/usr/local/bin/python3.1 # sample code to show version import sys print(sys.version_info) </code></pre> <p>In many case you would prefer not to <em>hardwire</em> the absolute path but manage use through the normal shell <code>PATH</code> environment variable. Traditionally <code>/usr/bin/env</code> is used for that purpose. However when running under <code>TextMate</code>, your shell profile files are not normally used so any changes to PATH do not show up there including possibly <code>/usr/local/bin</code> or <code>/opt/local/bin</code> or wherever your desired <code>python3</code> command is located. To get around that, you can add or modify a global <code>PATH</code> shell variable to <code>TextMate</code> -> <code>Preferences</code> (see above) with a value of, say, <code>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</code>. Then you can use a more general shebang line like this:</p> <pre><code>#!/usr/bin/env python3 </code></pre> <p>(This all seems to work with the most recent vanilla <code>TextMate</code> and its Python bundle: no guarantees about earlier versions or with other Python bundles.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload