Guido on python3 for beginners

Chris Angelico rosuav at
Thu Feb 18 06:07:05 EST 2016

On Thu, Feb 18, 2016 at 9:57 PM, Cem Karan <cfkaran2 at> wrote:
> I agree with Chris on all his points.  My personal feeling is that Py3 is the way to go for teaching in the future; its just that little bit more consistent across the board.  And the things that are confusing are not things that beginners will need to know about.
> About the only thing I've read where Py2 has a slight advantage is for scripts where you're suddenly surprised by Py2 starting up when you've been using a Py3 interactive interpreter.  For me, I'd probably give my students a block of code that they are asked to copy at the start of their files to test for Py2 or Py3, and to raise an exception on Py2.  After that, I just wouldn't worry about it.

Another solution is to have a little bit of boilerplate at the shell first:

python3 -m venv env
source env/bin/activate

Then both "python" and "python3" will run the binary from your virtual
environment, and as a side bonus, you get to use pip without root

By the way... For bash users, adding this to .bashrc may make venvs a
bit easier to keep straight:

checkdir() {
    [ -n "$VIRTUAL_ENV" ] && ! [[ `pwd` =~ `dirname $VIRTUAL_ENV`* ]]
&& echo Deactivating venv $VIRTUAL_ENV... && deactivate
    [ -z "$VIRTUAL_ENV" -a -d env ] && echo Activating venv
`pwd`/env... && source env/bin/activate

(I'm more fluent in Python than in bash, so this is a bit ugly.)

As soon as you change out of the directory that contains your venv,
it'll be deactivated, so you can't accidentally run stuff in the
"wrong" environment. And as soon as you change into a directory that
contains an 'env' subdir, it'll activate it. (Also applies on first
creation; as soon as "python3 -m venv env" returns, this will activate
the env.)


More information about the Python-list mailing list