How to find python installation directory on Ubuntu

629,842

Solution 1

First question:

which python though its usually /usr/bin/python for the 2.7

Second question:

From a terminal & python2.7: python2.7 yourfile.py.
Simailarly for 3.2: python3.2 yourfile.py though 3.2 isn't installed by default. (You can apt-get install python3.2.)

What python yourfile.py will do depends on which alternative is used for your python interpreter. You can change that by issuing update-alternatives python as root (or by using su).

Third question:

Environment variables are shell dependent, though you can write them out with echo $variable and set them with variable=value (from bash). The search path is simply called PATH and you can get yours by typing echo $PATH.

I hope this was helpful.

Solution 2

If you want to find the location of a program you can just use whereis <program>.

In your case run:

whereis python2.7
whereis python3.2

For finding every file that apt-get has copied for installation use:

dpkg -S python2.7
dpkg -S python3.2

But maby it is recommend to save it in a textfile, because the output is to large.

dpkg -S python2.7 >log.txt
gedit log.txt

for running .py file with python 3.2

python3.2 <file.py>

Solution 3

Here is a simple way, run in terminal:

type -a python

or

type -a python3

Solution 4

For Python2.7

whereis python2.7 

For Python3.2

whereis python3.2

For Python 3.8

which python3

or

whereis python3
Share:
629,842

Related videos on Youtube

avimehenwal
Author by

avimehenwal

Computer Engineer exploring new technologies and trying to understand them better. Technology appretiator and kneen learner. Javascript, Python developer. New to web developmetn and designing. Love artistic and creative job :D

Updated on September 18, 2022

Comments

  • avimehenwal
    avimehenwal over 1 year

    I have just migrated from Windows environment. I have installed Python 3.2 in a separate directory. How can I get the python installation path in Ubuntu shell?

    Is there any way I can let the shell know/choose at runtime which python version is to be used for further code execution?

    Are there any environment variables and search path kind of things in Ubuntu Linux as well?

  • avimehenwal
    avimehenwal about 11 years
    Thanks @Wolfer ! Answer was indeed helpful and much appreciated. If somebody like me has changed default python 3 installation path then .. ? How can I check path and run using this version ?
  • avimehenwal
    avimehenwal about 11 years
    Also, I am not getting any output for $echo $variable
  • avimehenwal
    avimehenwal about 11 years
    Thanks @Thomas ! This command 'whereis python2.7' is displaying many paths, but I think there has to be single python installation directory !
  • Thomas15v
    Thomas15v about 11 years
    dpkg -S python2.7 shows all the files of python2.7. "/usr/lib/python2.7" is the directory of python2.7.
  • avimehenwal
    avimehenwal about 11 years
    I m a bit confused, /usr/bin/python is the default shebang we use while python package is located at /usr/lib/python2.7 ? Is that true ??
  • Wolfer
    Wolfer about 11 years
    which python2.7 and which python3.2 will return each interpreter's install path (or return nothing if it's not installed).
  • Ravexina
    Ravexina over 3 years
    Doesn't really add anything to the other answers...
  • Admin
    Admin over 3 years
    @Ravexina Python 3.8 and made it little simple.
  • avimehenwal
    avimehenwal about 2 years
    This is a great answer. Old schooled bash to the rescue :D Thankyou for sharing
  • Danny Bullis
    Danny Bullis about 2 years
    A little bit of detail about what the type command is and what it does, particularly with the -a argument, would be helpful.