tags:

views:

417

answers:

2

Hello, how can I make setup.py file for my own script? I have to make my script global. (add it to /usr/bin) so I could run it from console just type: scriptName arguments. OS: Linux. EDIT: Now my script is installable, but how can i make it global? So that i could run it from console just name typing.

A: 

You should read about Python distutils, which will explain how to do that.

mipadi
+3  A: 

EDIT: This answer deals only with installing executable scripts into /usr/bin. I assume you have basic knowledge on how setup.py files work.

Create your script and place it in your project like this:

yourprojectdir/
    setup.py
    scripts/
        myscript.sh

In your setup.py file do this:

from setuptools import setup
# you may need setuptools instead of distutils

setup(
    # basic stuff here
    scripts = [
        'scripts/myscript.sh'
    ]
)

Then type

python setup.py install

Basically that's it. There's a chance that your script will land not exactly in /usr/bin, but in some other directory. If this is the case, type

python setup.py install --help

and search for --install-scripts parameter and friends.

Jasiu
Ok, i did that you wrote. But after running: setup.py install i got:<br />error: file '/home/ockonal/workspace/scripts/getkey.py' does not exist
Ockonal
Ok, i've already mady my script installable, but how can i make it global? I can't run it from console just name typing.
Ockonal
Where exactly was the script installed? If it's in /usr/bin, then setup.py works fine. Check your script's permissions - it should have +x permissions for everyone. The script in your project should have these persmissions, so that when it's copied to /usr/bin everything will be fine.
Jasiu
Yeah, now my script is in /usr/bin. I tried to do: chmod +x /usr/bin/scriptname.py. But after that there is still: comand not found for my script name in console.
Ockonal
The only other thing that comes to my mind is to check your PATH. Try running your script as /usr/bin/scriptname.py . If that works, but typing scriptname.py doesn't, then it's about PATH. Also, doublecheck that your script has #!/usr/bin/python in the first line.
Jasiu
And check permissions of your script in /usr/bin. Is it executable? Is it readable by everyone?
S.Lott