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>I made sure <code>install</code> was run with Python 3 and that the resulting script included the correct header. Still I kept getting exceptions from Python 2.7.</p>

<p>Out of desperation I created a new Python 3 virtual environment and in it the scripts started working properly. There are previous reports of old virtual environments going haywire, particularly <a href="http://stackoverflow.com/a/26499478/2066215">during a system upgrade</a>.</p>

<p>For future reference, the command I used:</p>

<p><code>mkvirtualenv -p /usr/bin/python3.5 venv_p3</code></p>

python python-3.x