Conda setuptools install将shebangs更改为默认python安装 [英] Conda setuptools install changes shebangs to default python install

查看:231
本文介绍了Conda setuptools install将shebangs更改为默认python安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,即通过setuptools安装到python anaconda的软件包会将shebangs重写到错误的位置.

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

我已经安装了python anaconda和setuptools软件包.我已验证python可执行文件指向anaconda可执行文件

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

我需要在我的anaconda python上安装一个自定义程序包.它只能通过setuptools安装.它包含一个命令行可执行文件,其顶部带有以下shebang:

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

可执行文件(content_analysis)出现在路径可访问的位置.但是顶部的shebang已替换为计算机上默认python安装的硬编码位置.

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

我已在此处阅读了以下有关setuptools覆盖shebangs的帖子.该帖子建议$PATH 中最先出现的python可执行文件应该是setuptools用于替换shebang的可执行文件.但是,对于我来说,情况似乎并非如此.

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.

注意:我无法将python可执行文件硬编码到我的python setup.py build命令中.我需要一个部署解决方案,该解决方案可以在已安装conda作为$PATH

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

推荐答案

我终于弄清楚是什么原因导致我在正确安装python和依赖项时遇到了所有问题:

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

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

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

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.

So, when sudo is invoked prior to sudo python setup.py the install is reverting back to the default python.

请参见这篇文章以进行讨论

这篇关于Conda setuptools install将shebangs更改为默认python安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆