Conda setuptools install changes shebangs to default python install
<p>I'm having an issue where packages installed via setuptools to python anaconda have shebangs rewritten to the wrong location.</p>

<p>I have installed python anaconda and setuptools package. I have verified that python executable points to the anaconda executable</p>

<pre><code>grant@DevBox2:/opt/content-analysis$ which python
/opt/anaconda2/bin/python
</code></pre>

<p>I need to install a custom package to my anaconda python. It is only installable via setuptools. It includes an command-line executable with the following shebang at the top:</p>

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

<p>After installing the package with the following command:</p>

<pre><code>sudo python setup.py install --prefix=/opt/anaconda2
</code></pre>

<p>The executable (content_analysis) appears in a path reachable location. But the shebang at the top has been replaced with the hard coded location of the default python install on the machine.</p>

<pre><code>grant@DevBox2:/opt/content-analysis$ which content_analysis
/opt/anaconda2/bin/content_analysis
grant@DevBox2:/opt/content-analysis$ sed -n 1,2p /opt/anaconda2/bin/content_analysis 
#!/usr/local/bin/python
</code></pre>

<p>I have read the following post <a href="http://stackoverflow.com/questions/1530702/dont-touch-my-shebang">here</a> concerning setuptools' overwrite of shebangs. The post suggests that the python executable that is first in the <code>$PATH</code> <em>should</em> be the executable that setuptools uses to replace the shebang. This doesn't seem to be the case for me however.</p>

<p>Note: I cannot hardcode a python executable into my <code>python setup.py build</code> command. I need a deployment solution that will work in any environment that has conda installed as the first python in the <code>$PATH</code></p>

<p>I finally figured out what has been causing all my issues getting python and dependencies properly installed:</p>

<p>Whenever <code>sudo</code> is invoked before an executable, in Debian the $PATH variable is automatically changed to a secure path lookup. Here is a demonstration:</p>

<pre><code>grant@DevBox2:/opt/content-analysis$ sudo sh
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
</code></pre>

<p>versus</p>

<pre><code>grant@DevBox2:/opt/content-analysis$ sh
$ echo $PATH
/opt/anaconda2/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
</code></pre>

<p>So, when sudo is invoked prior to <code>sudo python setup.py</code> the install is reverting back to the default python.</p>

<p>See <a href="http://unix.stackexchange.com/questions/83191/how-to-make-sudo-preserve-path">this post</a> for discussion</p>

python anaconda setuptools conda