On 8/17/12, debbym <de...@glance.net> wrote:
> I am new to both freebsd and python.
> I have python 2.6 and 3.2 both installed on freebsd.
> "python" runs python 2.6 and I need to use "python3.2" to run python 3.2
> Do I need to do something to make python 3.2 the default?

FreeBSD doesn't have an 'alternatives' system like debian flavors. However,
there's nothing wrong with your install. I run FreeBSD on several boxes. On
this box I have python 2.6, 2.7, and 3.2 installed. My default 'python'
executable is a symlink that points to /usr/local/bin/python, which itself is
version 2.6. (The box I'm on is FreeBSD 8.1)

If I want a program to run in python3.2, I put something like this (or
similar) as the shebang line at the top of the file:

    #!/usr/bin/evn python3.2

Or to get the interpretter just type 'python3.2'. Don't worry about the shebang
lines being cross platform either; Once you package up your scripts into python
packages, using distutils or similar, all shebang lines will be stripped. Upon
re-installation on the target platform they'll be replaced appropriately. (In
fact, some platforms even put 'env' in /bin instead of FreeBSD's /usr/bin.)

I would also recommend against changing the default 'python' symlink, as some
tools may depend on it being at a specific version. One I can think of off the
top of my head is the third party `xps` tool for searching ports. This is most
notable when talking about python2.x vs. the 3.x branch, as python 3 broke
backward compatibility with things like print statements becoming print
functions.

If you find it irritating to have to type 'python3.2' instead of just 'python',
you could create an alias for your shell, so that 'python' is aliased to
'python3.2'. I use tcsh, so I in my case my $HOME/.cshrc file might look
something like this:

    alias python /usr/local/bin/python3.2

Then I would type 'source .cshrc' or logout and back in for changes to take
affect. As an alternative, you could create a symlink from your own bin
directory instead. For example:

    cd
    mkdir bin
    ln -s /usr/local/bin/python3.2 ./bin/python

This should work once you type 'rehash' (in tcsh) or logout and log back in.
Most default installs will list the 'bin' directory, found in a given user's
home directory, on the default $PATH. You can verify this by typing 'echo
$PATH' and making sure '/home/<you>/bin' is listed. This isn't as good of an
option as simply using the alternate shebangs, as it affectively replaces your
version of python with the version you choose, but it will work.

Finally, if you want to get carried away, you can install a virtual python as
mentioned.

For even more options, you might subscribe to questi...@freebsd.org ;)
-Modulok-
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to