6

What is the process for running console scripts that use entry points as a python package developer?

I have a python project that has a setup.py with. In it, I have a

 entry_points={
        'console_scripts': [
            'myscript=mypackage.myscript.__main__:main',
        ]
    },

If I do python setup.py develop, I do end up with the wrapper scripts in virtualenv/bin, but when I run them I get an error:

ImportError: Entry point ('console_scripts', 'myscript') not found

(the above does work if I do pip install .)

Now, from the top of the project, I can copy the wrapper script and manually do:

$ python
Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pkg_resources import load_entry_point
>>> load_entry_point('mypackage', 'console_scripts', 'myscript')
<function main at 0x7f7b971bcea0>
>>> 

So, what I take from this is that virtualenv/bin/myscript is looking in the virtualenv for the package and when I run it manually from the top of my dev environment, it looks for packages in my current directory.

I don't want to run it out of my virtualenv though. I don't want to have to do pip install . every time I want to try a modification to my script.

What is the expected workflow here? To manually run python -m mypackage.myscript? I'd rather run it just like users will. Copy the virtualenv/bin scripts? Then they could become out of date...

I am unable to find this aspect of the development workflow in the setuptools docs.

update:

I did find this in my virtualenv after setup.py develop:

$ more virtualenv/lib/python3.6/site-packages/mypackage.egg-link
/home/me/src/mypackage.git
.
4
  • 3
    Normally it should work. Instead of ./setup.py develop try pip install -e . and see if that works any better. Commented Nov 13, 2019 at 17:12
  • 1
    Argh -- yes, that works. And then I pip uninstall mypackage and rerun setup.py develop and it still works as well. I'll see if I can reproduce. Commented Nov 13, 2019 at 17:16
  • AllI can guess was somehow my mypackage.egg-info/entry_points.txt was out of date. But can't reproduce it. Commented Nov 13, 2019 at 17:23
  • 2
    The console script entry point is just a shim (written out by then installer) which imports your Python function and runs it. It has a shebang that is associated with the Python executable which was used to install the distribution, so this will be the virtualenv's python if you installed package within the virtualenv. Ergo, you do not have to reinstall console_scripts every time you modify the library code. You only have to reinstall if adding/removing entry points. Voting to close as not reproducible. Commented Nov 13, 2019 at 17:23

1 Answer 1

10

As suggested by @Iguananaut, I ran pip install -e . instead.

It now works.

So I then did a pip uninstall mypackage and did a python setup.py develop again to reproduce. It didn't reproduce.

I now understand that load_entry_point literally reads the entry_points.txt from the mypackage.egg-info. My only guess is that somehow that file was bad... and not getting fixed by running python setup.py develop.

So -- the answer to my query is:

For running console scripts in a dev environment, use pip install -e . and run the scripts out of the virtualenv/bin/. It's designed to work that way, and if it doesn't -- something else is wrong.

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

2 Comments

Note that the load_entry_point thing is only used for editable installs. A normal install will not use this "hack", it will generate a proper script with library import.
In my case doing a pip install -e . doesn't work still and gives me and gives me a sys.exit(load_entry_point('fitbapp', 'console_scripts', 'manage-server')()) error. Can somebody help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.