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.
            Asked
            
        
        
            Active
            
        
            Viewed 4.8k times
        
    2 Answers
45
            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
        
- 2,674
- 2
- 27
- 27
3
            
            
        I know that this question is quite old, but just in case, I post how I solved the problem for myself, that was wanting to setup a package for PyPI, that, when installing it with pip, would install it as a system package, not just for Python.
setup(
    # rest of setup
    console_scripts={
        'console_scripts': [
            '<app> = <package>.<app>:main'
        ]
    },
)
- 
                    `` should be listed in `packages` keyword parameter of *rest of setup* part – Azat Ibrakov Aug 07 '18 at 14:08
 
     
     
    
error: file '/home/ockonal/workspace/scripts/getkey.py' does not exist – Max Frai May 17 '09 at 12:52