python setuptools removed shebang from my script

I have a script as such

from setuptools import setup

setup(
    name='my package',
    version='1.0',
    description='Bla',
    author='Me',
    url='http://www.google.com',
    packages=find_packages(),
    scripts=['bin/python_script_1', 'bin/python_script2'],
)

However the python script python_script_1 and python_script_2 both end up missing the shebang and become broken

source:

#!/bin/env python

"""
This script does things
"""

output:

#!

"""
This script does things
"""

I read the documentations (https://docs.python.org/3/distutils/setupscript.html#installing-scripts) that

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.

This is really confusing, why is my interpreter empty? How do I fix it? Is there some properties or environment variable I can set to fix this behavior?

What is the command that you run?

1 Like

Hi @merwok , the command I ran was from our shell script

PYTHONBUILDEXECUTABLE=/usr/bin/python3.6 ./entry_point.sh

and then the bash script will call

$PYTHONBUILDEXECUTABLE "$SCRIPT_DIR/setup.py"

and then in setup in py we see that invocation of setuptools.setup(…) function as above

thanks

Hi @merwok , the command I ran was from our shell script

PYTHONBUILDEXECUTABLE=/usr/bin/python3.6 ./entry_point.sh

and then the bash script will call

$PYTHONBUILDEXECUTABLE "$SCRIPT_DIR/setup.py"

and then in setup in py we see that invocation of setuptools.setup(…) function as above

thanks

Hi Peter, since you are using Python scripts anyway (and not arbitrary scripts, e.g. bash), have you considered using console_scripts entry-points?

This kind of script have much better support (pip will create an script wrapper automatically, with the correct shebang).

Some of the functionality of distutils is deprecated and might not work exactly as you expect for all the scenarios.

thanks @abravalheri , we found a code defect on our script elsewhere and that was causing the problem. Our setup.cfg was corrupted and provided empty build.executable. sorry for the trouble