简体   繁体   English

对于setup.py,如何将脚本的默认程序设置为当前的python解释器?

[英]For setup.py, how do you set a script's default program as the current python interpreter?

For example, lets say that the setup.py script is as follows 例如,假设setup.py脚本如下

from distutils.core import setup

setup(
    name='great_package_name',
    version='1.0',
    description='another great python package!',
    packages=['greatness'],
    scripts=['bin/some_script.py']
)

I want the bin/some_script.py to use the default program 我希望bin / some_script.py使用默认程序

/home/itzjustricky/anaconda2/envs/py33/bin/python

which is the python interpreter being used to call setup.py, ie 这是用于调用setup.py的python解释器,即

my-cpu: python setup.py
my-cpu: which python
/home/itzjustricky/anaconda2/envs/py33/bin/python

Is there a way so that setup.py automatically puts the 有没有办法让setup.py自动将

#!/home/itzjustricky/anaconda2/envs/py33/bin/python

header at the top of the bin/some_script.py file? bin / some_script.py文件顶部的标头? Also it would be great if setup.py got rid of the .py file extension as well. 同样,如果setup.py也摆脱了.py文件扩展名,那就太好了。

I could probably hack a way to use sys.executable to get the result, but is there a cleaner way? 我可能会破解一种使用sys.executable来获得结果的方法,但是有没有一种更清洁的方法? I am working in Python3. 我正在使用Python3。 Thank you for any help in advance! 预先感谢您的帮助!

I just realized that simply by putting 我只是意识到

#!/usr/bin/env python

at the head of the bin/some_script.py file solved my problem. 在bin / some_script.py文件的开头解决了我的问题。 I am not sure if anaconda is doing something behind the scenes. 我不确定anaconda是否在幕后做某事。 For getting rid of the extension, I just decided to name the some_script as bin/some_script from the start and that is good enough. 为了摆脱扩展名,我刚刚决定从一开始就将some_script命名为bin / some_script,这已经足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM