python setup.py安装更改脚本解释器 [英] python setup.py install changes script interpreter

查看:216
本文介绍了python setup.py安装更改脚本解释器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python软件包,该软件包在scripts/文件夹中包含一些脚本.我的setup.py文件包括::

I have a Python package that includes a few scripts in a scripts/ folder. My setup.py file includes::

#!/usr/bin/env python

from distutils.core import setup

scripts = ['script1', 'script2', 'script3']

setup(name='Test',
      version='0.1.0',
      packages=['test'],
      scripts=['scripts/' + x for x in scripts]
     )

每个脚本都包含以下行::

Each script contains the line::

#!/usr/bin/env python

在顶部.但是,当我运行python setup.py install时,此行将更改为::

at the top. However, when I run python setup.py install this line gets changed to::

#!/usr/bin/python

自动在已安装的脚本中.有办法避免这种情况吗?这对我来说是个问题,原因是我使用的是virtualenv,因此Python可执行文件的正确路径应为::

automatically in the installed scripts. Is there a way to avoid this? The reason that this is a problem for me is because I am using virtualenv, and so the correct path for the Python executable should be::

#/Users/user/.virtualenvs/default/bin/python

所以我宁愿将解释器设置为:

so I'd rather it left the interpreter set to::

#!/usr/bin/env python

感谢您的任何建议!

推荐答案

安装脚本检查python的安装位置,并将此python更改为正确的python.它会在安装软件包的每台机器上执行.

The install scripts checks, where the python is installed and changes this python to the proper one. It does it on every machine, where your package is installed.

来自文档:

脚本是包含Python的文件 源代码,打算开始 从命令行.脚本不 要求Distutils做任何事情 复杂.唯一聪明的功能 是如果第一行 脚本以#开头!并包含 单词"python",Distutils将 调整第一行以引用 当前口译员的位置.经过 默认情况下,它被替换为 当前口译员的位置.这 --executable(或-e)选项将允许解释器路径为 明确覆盖.

Scripts are files containing Python source code, intended to be started from the command line. Scripts don’t require Distutils to do anything very complicated. The only clever feature is that if the first line of the script starts with #! and contains the word "python", the Distutils will adjust the first line to refer to the current interpreter location. By default, it is replaced with the current interpreter location. The --executable (or -e) option will allow the interpreter path to be explicitly overridden.

这篇关于python setup.py安装更改脚本解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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