3

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?

12
  • Can you clarify what you want to do? An entry_point is not actually executed, it is merely a hook for other code to find it. If you mean that you define a console_scripts, that one simply uses the python version used to run setup.py. Just use your desired python version in this case. Overwriting sys.executable and the like is futile, as your process is already running. Commented Jul 11, 2018 at 12:40
  • Sorry if it was not clear. I have am generating the console script via console_scripts option inside entry_points. I have updated the question to clarify this. And the target python version is not available in the host, they are not even in the same path. Commented Jul 11, 2018 at 13:05
  • I do not understand. console_scripts is executed when installing, not when building. Whatever version is used on the target host to install, that one is used for console_scripts. How do you "generate" the console scripts? How do you install? Commented Jul 11, 2018 at 14:11
  • Let me explain what I am trying to do, I have a package in a mac host which should be build and installed in a directory which will be part of a BSP "Board Support Package" I am trying to automatically generate an entry point for my package which should run x.y.main. The problem here is that the path for the python interpreter is different in the mac host and the target board. I would like to have the entry point point to the correct python interpreter, so I need to somehow force a specific python interpreter in the generated script. Commented Jul 11, 2018 at 14:21
  • If you do not have access to the regular install machinery (which would create the script for you) build it on your development machine, and replace the shebang in the generated script. Commented Jul 11, 2018 at 15:23

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

Comments

0

Try

python setup.py build --executable /bin/custom_python
python setup.py install  # or bdist_egg/bdist_wheel

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.