Specify which Python version interprets an executable
<p>I developed an application with Python 3 that produces various executables. I then used <code>setuptools</code> to build and distribute this application, again all using Python 3.  </p>

<p>When this application is installed in a test environment, the executables are being correctly deployed to the <code>bin</code> folder and thus become invokable from anywhere in the system. However, when these executables are invoked, the system tries to use the Python 2 interpreter, leading to an exception. How can I make sure the Python interpreter is used when I invoke these executables?</p>

<p>You might need to use bash <a href="http://stackoverflow.com/questions/25165808/should-i-use-a-shebang-with-bash-scripts">shebangs</a> on your scripts, which are small strings at the beginning that specifies what binary should interpret them.</p>

<p>In your case you need to add <code>#!/usr/bin/env python3</code> at the beginning of your scripts. The bash shell should read this and pass the script to your <code>python3</code> installled interpreter.</p>

<p>Example:</p>

<pre><code>#!/usr/bin/env python3

# This should work on python3 and fail on python2:
print("Hello from python3!")  
</code></pre>

python python-3.x