Multiple python versions, one dev environment???

Javier nospam at nospam.com
Thu Jul 17 17:52:57 EDT 2014


> I can work with this (have not tried though), but there must be a
> more elegant solution than symlinking my way forward... 


I don't really understand what you are trying to do, but I would advise
to use environment variables to control the behaviour of the fake scripts
in /usr/local/bin

In bash you can do 

export PYVERSION=2.5

And from that time onwards everything defaults to python2.5.

note the ${PYVERSION} that I have included now in the sample scripts
below to select the python version.


I don't think you need to, but if you want to change the environment
variable inside python you can set environment variables with something like
os.environ.?????  Look at the docs.


Caveat1: I have not tested this, but it should work ok.  The setup I use is
much simpler: just default to python2.7

Caveat2: Arch linux packagers dont use a consistent naming of things:
There exists /usr/bin/virtualenv3, but there does not exist
/usr/bin/sphinx-build3 (it is /usr/bin/sphinx-build)
Somebody should send a bug to the package maintainer.

PS: Once you setup a workaround to bypass all the python=python3 nonsense,
Arch Linux is a nice linux distro, the best out there.  I will stick
to it.

HTH

========/usr/local/bin/python===========================================
#!/bin/bash
script=`readlink -f -- "$1"`
case "$script" in
/usr/bin*)
    exec python3 "$@"
    ;;
esac
exec python${PYVERSION} "$@"

========/usr/local/bin/virtualenv===========================================
#!/bin/bash
script=`readlink -f -- "$1"`
case "$script" in
/usr/bin*)
    exec virtualenv3 "$@"
    ;;
esac

exec virtualenv${PYVERSION} "$@"



Joep van Delft <joepvandelft at xs4all.nl> wrote:
> Hello Javier! 
> 
> Thanks, those links are helping a bit. And: yes, I am using Archlinux.
> 
> But still those links assume that there are totally separate
> site-packages* directories installed for both. I am not sure how I
> would surpass this distinction between py-X.P and py-Y.Q. 
> 
> Should I really create a massive amount of symlinks like this?: 
> 
> | #!/usr/bin/zsh
> | for d in ~/src/mypackage/**/*(/); do 
> |    # matches all directories
> |    mkdir -p "~/src/py-2.7/mypackage/${d#*src/mypackage}"
> |    mkdir -p "~/src/py-3.4/mypackage/${d#*src/mypackage}"
> | done
> | for f in ~/src/mypackage/**/^*.pyc(.); do 
> |    # matches all files except for *.pyc
> |    ln -s "$f" "~/src/py-2.7/mypackage${f#*src/mypackage}"
> |    ln -s "$f" "~/src/py-3.4/mypackage${f#*src/mypackage}"
> | done
> 
> ...and then set $PYTHONPATH according to the target version in a
> #!/usr/local/bin-script? 
> 
> I can work with this (have not tried though), but there must be a
> more elegant solution than symlinking my way forward... 
> 
> Cheers!
> 
> 
>    Joep
> 



More information about the Python-list mailing list