1

I wrote a piece of code with a setup.py

entry_points = {'gui_scripts': ['mycode = mycode.__main__:main',],},

I would like to be able to call it with the command mycodeinstead of python -m mycode

The __main__.py starts with the shebang #!/usr/bin/env python

Do you know how to do that?

(I use python3.7 on a fresh install of Archlinux)

1 Answer 1

1

If you "install" your Python module, you'll be able to do this.

These assume that you still want to be able to edit your code wherever you have it on your local machine:

# doing it in a non-global way (i.e., just for the current user)
# from the directory containing your "setup.py" file
pip install --user -e .

# and as long as ~/.local/bin is in your path:
mycode

If you want to make it available to every user on the machine,

# install an "editable" copy of the code from the current directory
# into the global Python installation
pip install -e .

# this will install it next to pip and your other Python tools
mycode

Note you don't need to specify main in your setup.py either:

entry_points = {'gui_scripts': ['mycode = mycode:main',],},
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was just missing the path in my bashrc pointing to ~/.local/bin. Awesome!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.