Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python pip configure python executable for entry_points

I have a package which I am building locally to use inside an embedded environment.

I am trying to generate a console script automatically, so I am using console_scripts inside entry_points like the following:

setup(...,
    entry_points={
        'console_scripts': [
                'app=x.y:main'
        ]
    },
    # Below is added as the other tried methods failed.
    options={
        'build_scripts': {
            'executable': '/bin/custom_python',
        },
    }
)

I am trying to set the python interpreter used in my entry_point as it is different than the one inside the build system. But no matter what I try it keeps set to the local interpreter.

I tried several options like:

  1. Setting an interpreter in shebang header in setup.py
  2. Setting sys.executable inside setup.py
  3. Using options={'build_scripts': {'executable': 'bin/custom_python'}}
  4. Using pip install --global-option=build --global-option='--executable=/bin/custom_python'

But none of the above worked. I wonder if there is something I am missing?

like image 257
silentnights Avatar asked Mar 30 '26 01:03

silentnights


1 Answers

So finally I managed to do it.

First I had to add the following to my setup call, which is suggested in various posts:

options={
    'build_scripts': {
        'executable': '/bin/custom_python',
    },
}

Now I build and install the package as usual. In my case, I create a wheel and install it:

python3 setup.py sdist bdist_wheel -d wheels 
pip3 install --no-deps -U --prefix $TARGET_INSTALL wheels/mypackage.whl

The above will use the local python interpreter for the created scripts

To fix that I run the following:

python3 setup.py install_scripts -d $TARGET_INSTALL/bin

which replaces the scripts with the correct ones passed in 'build_scripts' option.

But I am still wondering if there is a way to get the correct interpreter directly when installing the wheel with pip?

like image 114
silentnights Avatar answered Apr 02 '26 04:04

silentnights



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!