简体   繁体   中英

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

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

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

which is the python interpreter being used to call setup.py, ie

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

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

header at the top of the bin/some_script.py file? Also it would be great if setup.py got rid of the .py file extension as well.

I could probably hack a way to use sys.executable to get the result, but is there a cleaner way? I am working in 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. I am not sure if anaconda is doing something behind the scenes. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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