Search code examples
pythonbinaryinstallationpipsudo

How can I execute a binary file located in the installation directory of my Python package (without sudo)


Let's say I have a Python package structure like that:

top-level/
    __init__.py
    utilities.py
    myscript.py
    binaryfile
LICENSE.txt
MANIFEST.in
README.rst
setup.cfg
setup.py

When I installed the package it will be located in:

/usr/local/lib/python2.7/dist-packages/mypackage/

and the path of binary file will be:

/usr/local/lib/python2.7/dist-packages/mypackage/binaryfile

My question is: How can I execute this binary file that located under /usr/local/... without root privileges (without sudo) from a script located in my package.

I'm using my package as a console script so instead of using:

sudo mypackage

to run my package, I wanna use only:

mypackage

Solution

  • You want to give execute permission to normal users, so running

    sudo chmod +x /usr/local/lib/python2.7/dist-packages/mypackage/binaryfile
    

    once should make it possible for normal users to execute it.