I installed a program that requires you to execute a python script like this:

python fit_locus.py --help

I want to make the file acessible to all users without requiring them to navigate to the folder of the python file, so they can execute said command from their home folders.

I tried adding the install folder to the PATH variable and tried to create a symlink of the file in /bin and /usr/bin but it didn't work.

Is it possible to do so or should I require the users to navigate to the folder where the program is installed?

EDIT: Here's my PATH variable:

Without the export:


With the export:


And the path /opt/big-macs/calibrate/ is the one that contains the python script fit_locus.py


On the installation instructions of the program I'm trying to make available to all users there's this little guide:

Set environmental variables:

1 - BIGMACS to the path of the installation directory


setenv BIGMACS /Users/ronald/big-macs-calibrate/ (tcsh shell)      
BIGMACS=/Users/ronald/big-macs-calibrate/ (bash shell)
export BIGMACS

2 - add installation directory to PYTHONPATH



But it doesn't work either. The error I get when I try to run python fit_locus.py --helpis:

python: can't open file 'fit_locus.py': [Errno 2] No such file or directory
  • Please post your PATH variable – Rahul May 5 '16 at 12:20
  • Without the export: /gasgano/bin:/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/esoreflex/bin:/opt/intel/composer_xe_2011_sp1.9.293/mpirt/bin/intel64 – JefersonFG May 5 '16 at 12:22
  • With the export: /gasgano/bin:/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/esoreflex/bin:/opt/intel/composer_xe_2011_sp1.9.293/mpirt/bin/intel64:/opt/big-macs-calibrate/ – JefersonFG May 5 '16 at 12:23
  • /opt/big-macs/calibrate/ contains the python script fit_locus.py – JefersonFG May 5 '16 at 12:23
  • Don't post it as comment, edit here – Rahul May 5 '16 at 12:24

To make something like this easily executable, add this as the first line of the python script:

#! /usr/bin/python

and the file itself should be executable; that is, the x bits must be set, chmod +x fit_locus.py.

Since the script is in the amended PATH, users can just enter the name. For simplicity, you can remove the '.py' so users only need to type

fit_locus --help

unless there's a reason you want the users to be aware that it's a python script.

  • 1
    !#/usr/bin/env python can also be used, in case the python executable doesn't reside in /usr/bin – Joe May 5 '16 at 20:50
  • Neither worked out. I added the line you mentioned in the start of the script, used chmod +x, exported the PATH and tried to execute the file and it says "fit_locus: command not found" – JefersonFG May 6 '16 at 12:33
  • Here's the output: root@astrolab15:~# vim /opt/big-macs-calibrate/fit_locus.py root@astrolab15:~# chmod +x /opt/big-macs-calibrate/fit_locus.py root@astrolab15:~# export PATH=$PATH:/opt/big-macs-calibrate/ root@astrolab15:~# fit_locus --help fit_locus: command not found – JefersonFG May 6 '16 at 12:33
  • Ah! I was unclear. You have to remove the .py suffix by renaming the file, removing it from both the filename and what the user types. Right now, the user should be able to type fit_locus.py --help, but after you mv fit_locus.py fit_locus then the shell will find it. – stolenmoment May 6 '16 at 13:24
  • Still didn't work, same error as before (command not found) – JefersonFG May 16 '16 at 19:47

An alternate way is to create a desktop launcher. That could specify the exact path to the file. The launcher could then be copied to each user's desktop. Another approach is a smaller starter script to go into each user's home folder. But then you have to use ./, ~/, or $HOME/ before the script name to launch it.

However, you can add folders to either the head or tail end of $PATH for each user if you modify the .bashrc or the .profile for each user. This is a permanent change that takes effect each time they log in. So there are options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.