Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 on ubuntu shell ?

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

Are there any kind of environment variables and search path kind of thing in ubuntu linux as well ?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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 update-alternatives python if I'm right.

Third question: environment variables are shell dependant, though you can echo them with echo $variable and set them with variable=value (from bash). The serch path in linux is simply called PATH and you can get yours by echo $PATH.

I hope this was helpful.

share|improve this answer
    
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 ? –  Avi Mehenwal Feb 27 '13 at 19:56
    
Also, I am not getting any output for $echo $variable –  Avi Mehenwal Feb 27 '13 at 19:59
2  
which python2.7 and which python3.2 will return each interpreter's install path (or return nothing if it's not installed). –  Wolfer Mar 2 '13 at 17:18

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>
share|improve this answer
    
Thanks @Thomas ! This command 'whereis python2.7' is displaying many paths, but I think there has to be single python installation directory ! –  Avi Mehenwal Feb 27 '13 at 20:08
1  
dpkg -S python2.7 shows all the files of python2.7. "/usr/lib/python2.7" is the directory of python2.7. –  Thomas15v Feb 27 '13 at 20:12
    
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 ?? –  Avi Mehenwal Feb 27 '13 at 20:25
    
/usr/lib/python is the program. In linux evry file can be a program. If you come from window it is confused. –  Thomas15v Feb 27 '13 at 20:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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