Conda setuptools install changes shebangs to default python install

时间:2016-08-31 17:23:15

标签: python anaconda setuptools conda

I'm having an issue where packages installed via setuptools to python anaconda have shebangs rewritten to the wrong location.

I have installed python anaconda and setuptools package. I have verified that python executable points to the anaconda executable

grant@DevBox2:/opt/content-analysis$ which python
/opt/anaconda2/bin/python

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:

#!/usr/bin/env python

After installing the package with the following command:

sudo python setup.py install --prefix=/opt/anaconda2

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.

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

I have read the following post here concerning setuptools' overwrite of shebangs. The post suggests that the python executable that is first in the $PATH should be the executable that setuptools uses to replace the shebang. This doesn't seem to be the case for me however.

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

1 个答案:

答案 0 :(得分:2)

我终于找到了导致我所有问题正确安装python和依赖项的原因:

每当在可执行文件之前调用sudo时,在Debian中,$ PATH变量会自动更改为安全路径查找。这是一个演示:

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

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

因此,当在sudo python setup.py之前调用sudo时,安装将恢复为默认的python。

请参阅this post进行讨论