[arch-general] An archlinux-python package for managing system default python version?

Borja borja at libcrack.so
Fri Jan 23 16:57:43 UTC 2015


Does this .bashrc hack for for you maybe? :-)


## Toogle between python versions
python-toggle(){

    local RED="\e[0;31m"
    local GREEN="\e[0;32m"
    local RESET="\e[0;0m"

    test -z "$1" || v="$1"
    local bins=('python' 'python-config' 'pip')
    cd /usr/bin
    for bin in ${bins[@]}; do
        test -h $bin || {
            echo -e "${RED}ERROR:${RESET} cannot find $PWD/$bin"
            return 1
        }
    done
    echo -e ">> ${RED}Disabling $(python -V 2>&1)${RESET}\007"
    if [[ python -ef python3 || "python${v}" == "python3" ]]; then
        rm python python-config pip
        ln -s python2 python
        ln -s python2-config python-config
        ln -s pip2 pip
    elif [[ python -ef python2 || "python${v}" == "python2" ]]; then
        rm python python-config pip
        ln -s python3 python
        ln -s python3-config python-config
        ln -s pip3 pip
    else
        echo -e "${RED}ERROR:${RESET} cannot find link /usr/bin/$bin"
        cd - > /dev/null
        return 2
    fi
    echo -e ">> ${GREEN}Enabled $(python -V 2>&1)${RESET}\007"
    cd - > /dev/null
}


El vie, 23-01-2015 a las 21:51 +0800, Chi Hsuan Yen escribió:
> Dear Arch enthusiasts,
> 
> The package extra/java-runtime-common provides a convenient script
> archlinux-java to handle co-existing JDK/JRE versions. I can use it to
> switch between different versions of java implementations to accomplish
> numerous tasks from testing the compatibilities of my programs to running
> third party applications targeting on different platforms. Now I hope
> there's also a simple script for the same thing but for python. On the
> system, most of the scripts are written for python2 and some other scripts
> are python3-specific. In most cases it's not a problem because I can fix
> the scripts or use some tricks like $PATH to ensure the correct execution
> of the programs. However, in large projects, doing either is time-consuming
> and costly. Recently I'm building CyanogenMod on Arch Linux. It includes
> lots of python scripts in the build system, and most of them requires
> python2. Using the tip provided on the article about Python on ArchWiki
> prevents lots of problems, but, however, some scripts have the shebang line
> "#!/usr/bin/env python" or are invoked by some command like
> "/usr/bin/python ...". I have to change the link /usr/bin/python to
> pointing to python2 for further progress on building and changed it back
> for my daily use. If there's an archlinux-python script, lots of time on
> battling the difference between python2 and python3 does not exist anymore,
> which I believe lots of users can benefit from it. Any ideas?
> 
> Best Regards,
> 
> Yen Chi Hsuan

-- 

======================================================================

 GPG 0x8C00BA074CA6E08B -- https://www.libcrack.so/


More information about the arch-general mailing list