Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 2654  / 2 Years ago, fri, june 3, 2022, 9:27:27

I have been fiddling with my Python installation on Ubuntu 12.04 (I was having trouble installing a python library), and at one point my python command wasn't working. It turned out the symlink was missing (I must have removed it by accident lol), so I made a new one pointing to Python 3.2 (originally pointed to 2.7):



sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.2 /usr/bin/python


Problem: the software center and update manager weren't working:



~$ software-center
File "/usr/bin/software-center", line 152
print time.time()
^
SyntaxError: invalid syntax


I guessed this was because I had changed the default python version (2.7->3.2), so I changed it back to 2.7. Now they work fine, but I'd still like to change the 'default' python version (i.e. the one called with python in the terminal).



Is it possible to do that in Ubuntu 12.04?

Thanks!


More From » 12.04

 Answers
4

You shouldn't change the symlink for python to point to Python 3 as you have already seen its consequences. And I would recommend you to get into the habit of calling Python 3 programs with python3 as that would involve the least amount of trouble later on.



But if you insist on calling Python 3 on your Terminal using python, you may create an alias for it. Remember, alias is different than symlink. Edit ~/.bash_aliases file (create it if it doesn't exist) to add the following in it:



alias python='python3.2'


Then restart your terminal and you would be able to execute Python 3 by calling python. This wouldn't break anything as changing the symlink does.



You may even add aliases like alias py3='python3.2' and then call py3 to run Python 3. This is even shorter and less confusing.


[#24399] Saturday, June 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanda

Total Points: 439
Total Questions: 116
Total Answers: 105

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;