Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find where Python is located on Unix?

I'm working on a new server for a new workplace, and I'm trying to reuse a CGI script I wrote in Python earlier this year. My CGI script starts off with

#!/local/usr/bin/python

But when I run this on the new server, it complains that there's no such folder. Obviously Python's kept in a different place on this box, but I've got no idea where.

I haven't done much unix before, just enough to get around, so if there's some neat trick I should know here I'd appreciate it :)

Thanks!

like image 376
Adam Avatar asked Dec 07 '10 04:12

Adam


People also ask

How do I know where Python is installed in Unix?

One of the most important things to note when you are adding Path to Python in Unix or Linux is that, /usr/local/bin/python is the default path of the Python directory.

How can I find where Python is installed on Linux?

If the Python installation was done from sources or from Python installation mechanisms (like easy_install or Python setup.py) and not from a packages manager like apt-get or aptitude among others, Python packages are stored under the /usr/local/lib/python<version>/ directory.

How do I find the path where Python is installed?

py installed location is C:\Windows\py.exe if installed for all users, otherwise can be found at C:\Users\username\AppData\Local\Programs\Python\Launcher . It does not require the environment PATH variable to be set if installed for all users.

Is Python installed on Unix?

Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features you might want to use that are not available on your distro's package. You can easily compile the latest version of Python from source.


2 Answers

Try:

which python

in a terminal.

like image 200
icyrock.com Avatar answered Oct 12 '22 23:10

icyrock.com


For this very reason it is recommend that you change your shebang line to be more path agnostic:

#!/usr/bin/env python

See this mailing list message for more information:

Consider the possiblities that in a different machine, python may be installed at /usr/bin/python or /bin/python in those cases, #!/usr/local/bin/python will fail. For those cases, we get to call the env executable with argument which will determine the arguments path by searching in the $PATH and use it correctly.

(env is almost always located in /usr/bin/ so one need not worry that env is not present at /usr/bin.)

like image 30
John Kugelman Avatar answered Oct 12 '22 23:10

John Kugelman