How to change the default version of Python in Debian 7.5?

10,325

To change the version of python that is executed when you type python on the command line, and only then, define an alias in your shell initialization file (the one for interactive shells). This is ~/.bashrc for bash, ~/.zshrc for zsh, ~/.cshrc for csh, ~/.config/fish/config.fish for fish. Use the correct path for Python 3.3 for your installation.

alias python='/usr/local/bin/python3.3'

If you want this to work for all users, you can put it in a system-wide file; however I don't recommend it, because this causes python typed on the command line to be a different version from python executed from a script or any other place, which is confusing.

In Debian wheezy, python in the default search path should be Python 2.7, because there are programs that depend on it (several packages ship Python 2 scripts that have #!/usr/bin/env python as their shebang line). If you want, you can change the system default for Python 3 to be Python 3.3 instead of the 3.2 that ships with Debian wheezy. To do that, create a symbolic link in /usr/local/bin (you'll need to be root to do this). If you installed Python 3 in directly in /usr/local:

ln -s python3.3 /usr/local/bin/python3

If you installed it somewhere else:

ln -s /path/to/python3.3/bin/python3.3 /usr/local/bin/python3

Scripts that ship with Debian with the shebang #!/usr/bin/python3 will keep using 3.2, but scripts that use #!/usr/bin/env python3 will now use 3.3, and typing python3 on the command line will invoke 3.3.

Share:
10,325

Related videos on Youtube

wolf_adventures1909
Author by

wolf_adventures1909

Web developer, and avid fan of Linux, currently using Debian 7.5. I've been learning about web development since Sept 2013. Since then I have learned PHP, Python, switched from Windows to Linux and fixed my bootloader more times than I can remember!

Updated on September 18, 2022

Comments

  • wolf_adventures1909
    wolf_adventures1909 over 1 year

    I'm using Debian 7.5, and I've installed Python 3.3 and 3.2. How do I make 3.3 the default for when someone types python in the command line?