Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setup.py and adding file to /bin/

Tags:

python

I can't figure out how to make setup.py add a scrip to the the user's /bin or /usr/bin or whatever.

E.g., I'd like to add a myscript.py to /usr/bin so that the user can call myscript.py from any directory.

like image 455
Aaron Yodaiken Avatar asked Jan 29 '11 23:01

Aaron Yodaiken


People also ask

How do I use setup py files?

Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

What goes in a setup py file?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.

What does setup py Sdist do?

(assuming you haven't specified any sdist options in the setup script or config file), sdist creates the archive of the default format for the current platform. The default format is a gzip'ed tar file ( . tar. gz ) on Unix, and ZIP file on Windows.


2 Answers

Consider using console_scripts:

from setuptools import setup setup(name='some-name',       ...       entry_points = {               'console_scripts': [                   'command-name = package.module:main_func_name',                                 ],                         }, ) 

Where main_func_name is a main function in your main module. command-name is a name under which it will be saved in /usr/local/bin/ (usually)

like image 153
DataGreed Avatar answered Sep 19 '22 04:09

DataGreed


The Python documentation explains it under the installing scripts section.

Scripts are files containing Python source code, intended to be started from the command line.

setup(...,       scripts=['scripts/xmlproc_parse', 'scripts/xmlproc_val'] ) 

As mentioned here, beside scripts, there is an entry_points mechanism, which is more cross-platform.

With entry_points you connect a command line tool name with a function of your choice, whereas scripts could point to any file (e.g. a shell script).

like image 32
miku Avatar answered Sep 21 '22 04:09

miku