Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's because subprocess doesn't load a shell by default (see <a href="http://docs.python.org/2/library/subprocess.html#subprocess.check_call" rel="nofollow">the docs</a>), so it doesn't get what's in your .bash_profile. Use this:</p> <pre><code>subprocess.check_call(args = ["python3.3", onePyFile], shell=True) </code></pre> <p>Edit: Seems like glasslion was faster than me!</p> <p>Edit 2: I did a bit more digging around, and found something strange. Because shell=True didn't seem to work as expected I went with a more direct approach, calling bash directly.</p> <p>a.py:</p> <pre><code>from subprocess import check_call check_call(['bash', '-c', '. ~/.bash_profile &amp;&amp; ABC a bc']) </code></pre> <p>a.sh (what would be your python3 executable):</p> <pre><code>echo $* </code></pre> <p>I first tried with <code>alias ABC='~/Documents/a.sh'</code> in <code>.bash_profile</code>:</p> <pre><code>$ python ~/Documents/a.py bash: ABC: command not found Traceback (most recent call last): File "Documents/a.py", line 6, in &lt;module&gt; check_call(['bash', '-c', '. ' + expanduser('~/.bash_profile') + ' &amp;&amp; ABC a bc']) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 511, in check_call subprocess.CalledProcessError: Command '['bash', '-c', '. ~/.bash_profile &amp;&amp; ABC a bc']' returned non-zero exit status 127 </code></pre> <p>Then I switched from an alias to a function: <code>ABC() { ~/Documents/a.sh $*; }</code> And it worked!</p> <pre><code>$ python ~/Documents/a.py a bc </code></pre> <p>Bottom line is I got it to work, but I don't know why! Shells aren't reliable, so the best would be to skip the shell.</p> <p>We can do that by using the shebang's principle (as Fred Mitchell suggested) in a clever way:</p> <pre><code>from subprocess import check_call check_call(['/usr/bin/env', 'python3', onePyFile]) </code></pre> <p>This will work if Python 3 was installed correctly, independently of it's path (what I suppose you wanted to achieve).</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