Change Default Python Version from 2.4 to 2.6

Change default Python version from 2.4 to 2.6

As root:

ln -sf /usr/bin/python2.6 /usr/local/bin/python

This will make a symbolic link from /usr/local/bin/python --> /usr/bin/python2.6
(replacing the old hardlink).

Two versions of python on linux. how to make 2.7 the default

You probably don't actually want to change your default Python.

Your distro installed a standard system Python in /usr/bin, and may have scripts that depend on this being present, and selected by #! /usr/bin/env python. You can usually get away with running Python 2.6 scripts in 2.7, but do you want to risk it?

On top of that, monkeying with /usr/bin can break your package manager's ability to manage packages. And changing the order of directories in your PATH will affect a lot of other things besides Python. (In fact, it's more common to have /usr/local/bin ahead of /usr/bin, and it may be what you actually want—but if you have it the other way around, presumably there's a good reason for that.)

But you don't need to change your default Python to get the system to run 2.7 when you type python.


First, you can set up a shell alias:

alias python=/usr/local/bin/python2.7

Type that at a prompt, or put it in your ~/.bashrc if you want the change to be persistent, and now when you type python it runs your chosen 2.7, but when some program on your system tries to run a script with /usr/bin/env python it runs the standard 2.6.


Alternatively, just create a virtual environment out of your 2.7 (or separate venvs for different projects), and do your work inside the venv.

Changing Fast CGI to run a different version of python

On my system which is hosted on tigertech.net (a pretty vanilla hosting service), I configured using excellent advice from

http://www.codekoala.com/blog/2008/installing-django-shared-hosting-site5/

You just need to make sure that the "she-bang" (first line in the .fcgi file) correctly identifies the version of python you want to run.

Assuming that the 2.6 install is located in /usr/bin/python26/, you would then have

#!/usr/bin/python26/python

as the first line of your fcgi file, instead of whatever you have right now. That tells the server which version of python (or whatever) you want the script to be run under.

How to use a different version of python during NPM install?

You can use --python option to npm like so:

npm install --python=python2.7

or set it to be used always:

npm config set python python2.7

Npm will in turn pass this option to node-gyp when needed.

(note: I'm the one who opened an issue on Github to have this included in the docs, as there were so many questions about it ;-) )

How do I set the driver's python version in spark?

You need to make sure the standalone project you're launching is launched with Python 3. If you are submitting your standalone program through spark-submit then it should work fine, but if you are launching it with python make sure you use python3 to start your app.

Also, make sure you have set your env variables in ./conf/spark-env.sh (if it doesn't exist you can use spark-env.sh.template as a base.)

What version of Python (2.4, 2.5, 2.6, 3.0) do you standardize on for production development efforts (and why)?

I wouldn't abandon 2.6 just because of deprecation warnings; those will disappear over time. (You can use the -W ignore option to the Python interpreter to prevent them from being printed out, at least) But if modules you need to use actually don't work with Python 2.6, that would be a legitimate reason to stay with 2.5. Python 2.5 is in wide use now and probably will be for a long time to come (consider how long 2.3 has lasted!), so even if you go with 2.5, you won't be forced to upgrade for a while.

I use Python 2.5 for all my development work, but only because it's the version that happens to be available in Gentoo (Linux)'s package repository. When the Gentoo maintainers declare Python 2.6 "stable"*, I'll switch to that. Of course, this reasoning wouldn't necessarily apply to you.

* Python 2.6 actually is stable, the reason it's not declared as such in Gentoo is that Gentoo relies on other programs which themselves depend on Python and are not yet upgraded to work with 2.6. Again, this reasoning probably doesn't apply to you.

switch versions of python

Use Virtualenv.

There is more information here: Working with virtualenv.

Using virtualenv you can create a new virtual python environment with whatever version of Python you want for each project or application. You can then activate the appropriate environment when you need it.

To expand on my answer:

You can install multiple versions of Python on your computer (I have 2.4, 2.5, 2.6 and 3.1 on my machine - I install each from source). I use a Mac, and keep my system Python as whatever OS X sets as the default.

I use easy_install to install packages. On ubuntu you can get easy_install like this:

sudo apt-get install python-setuptools

To install virtualenv then do:

easy_install virtualenv

I tend to create a new virtualenv for each project I'm working on and don't give it access to the global site-packages. This keeps all the packages tight together and allows me to have the specific versions of everything I need.

virtualenv -p python2.6 --no-site-packages ~/env/NEW_DJANGO_PROJECT

And then whenever I am doing anything related to this project I activate it:

source ~/env/NEW_DJANGO_PROJECT/bin/activate

If I run python now it uses this new python. If I use easy_install it installs things into my new virtual environment.

So, virtualenv should be able to solve all of your problems.



Related Topics



Leave a reply



Submit