3

How do I make a python script a unix-able command?

Let's say i have a python script:

print "hello foo bar"

and i want to call the python script like a normal linux command, something that people can:

deb www.myfoobar.com foobar
deb-src www.myfoobar.com foobar
sudo apt-get install foobar

Then after installation, something that someone can just call from terminal:

$ foobar
hello foo bar
5
  • 1
    That's a lot of steps. Are you asking how to create a deb? How to host a deb on your website? How to store the script in a file? Commented Sep 18, 2013 at 13:40
  • All you have to do is to put the script at a System level searchable path and change its mode to execuatable. Commented Sep 18, 2013 at 13:42
  • @falsetru had answer how to store the script into a command. How do i create and host a deb? Commented Sep 18, 2013 at 13:42
  • 1
    You don't. Use Launchpad instead. Commented Sep 18, 2013 at 13:43
  • There are lots of online resources to explain how to create your own deb file and repository. A quick google search turns up, for example, community.linuxmint.com/tutorial/view/162 and impermium.com/blog/hosting-deb-packages-locally, and many other options. Commented Sep 18, 2013 at 13:47

3 Answers 3

6

Put following shebang line at the top of the script.

#!/usr/bin/env python

Make a script executable using following command:

chmod +x foobar

Move the script to somewhere in the $PATH (for example: /usr/local/bin)

mv foobar /usr/local/bin

From Rob: For the creating and hosting a deb problem, you can use external services such as https://launchpad.net/ubuntu

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't address how to run sudo apt-get install.
2

Here is a complete walk through for creating an Ubuntu package and submitting it for consideration. Debian has it's own procedures. Of course if you just want to make a Python script into a Unix command then you might also just want to package it using setuptools, submit it to PyPi and let people pip install <package>.

Comments

0

If you wan't to distribute your script, so you can download it, you have to create a package (.rpm on linux).

1 Comment

The native package format is .rpm on Redhat and similar distros. It is .deb on Debian, Ubuntu and distros derived therefrom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.