[Python-es] /usr/bin/python2

Narcis Garcia - GiLUG informatica en actiu.net
Lun Feb 7 14:28:37 CET 2011


Bueno, tuve que corregir algunas imperfecciones del programa-lanzador. 
Aqui va la revision:

#!/bin/sh
# Lanzador de programa con su version de Python
# Version 2011.02.07
# Copyright (GNU GPL) Narcis Garcia

EjecutableLanzar="./gsciber.py"
VersionDeseadaPython="2"

# Busqueda de componentes
Result=0
RutaPython="$(which python)"
Alternativas=""
AlternativaActual=""
VersionPython=""

if [ "$(which $EjecutableLanzar)" != "" ] ; then
     if [ "$RutaPython" != "" ] ; then
         if [ "$VersionDeseadaPython" != "" ] ; then
             if [ "$(which python${VersionDeseadaPython})" != "" ] ; then
                 RutaPython="$(which python${VersionDeseadaPython})"
             else
                 Alternativas="$(ls -1 ${RutaPython}* | grep -ie 
"${RutaPython}${VersionDeseadaPython}")"
                 if [ "$Alternativas" != "" ] ; then
                     for AlternativaActual in $Alternativas ; do
                         if [ "$(which $AlternativaActual)" != "" ] ; then
                             RutaPython="$AlternativaActual"
                         fi
                     done
                 fi
             fi
             VersionPython="$($RutaPython --version 2>&1)"
             VersionPython="$(UnaPalabra () { echo $2; }; UnaPalabra 
$VersionPython)"
             if [ "$(echo "$VersionPython" | grep -ie 
"^$VersionDeseadaPython")" = "" ] ; then
                 xmessage "ADVERTENCIA: Se necesita Python 
$VersionDeseadaPython para que el programa funcione correctamente.
$EjecutableLanzar se va a lanzar con Python $VersionPython"
             fi
         fi
         echo "\"$RutaPython\" \"$(which "$EjecutableLanzar")\""
         "$RutaPython" "$(which "$EjecutableLanzar")"
         Result=$?
     else
         xmessage "PROBLEMA: No se encuentra el interprete Python.
SOLUCION: Pruebe a instalar el paquete \"python\"."
         Result=1
     fi
else
     xmessage "PROBLEMA: No se encuentra el programa $EjecutableLanzar"
     Result=1
fi
exit $Result




Al 07/02/11 14:10, En/na Narcis Garcia - GiLUG ha escrit:
> Aqui va el codigo de un lanzador estandar:
>
> #!/bin/sh
> # Lanzador de programa con su version de Python
> # Version 2011.02.07
> # Copyright (GNU GPL) Narcis Garcia
>
> EjecutableLanzar="miprograma.py"
> VersionDeseadaPython="2"
>
> # Busqueda de componentes
> Result=0
> RutaPython="$(which python)"
> Alternativas=""
> AlternativaActual=""
> VersionPython=""
>
> if [ "$(which $EjecutableLanzar)" != "" ] ; then
>     if [ "$RutaPython" != "" ] ; then
>         if [ "$VersionPython" != "" ] ; then
>             if [ "$(which python${VersionPython})" != "" ] ; then
>                 RutaPython="$(which python${VersionPython})"
>             else
>                 Alternativas="$(ls -1 ${RutaPython}* | grep -ie 
> "${RutaPython}${VersionPython}")"
>                 if [ "$Alternativas" != "" ] ; then
>                     for AlternativaActual in $Alternativas ; do
>                         if [ "$(which $AlternativaActual)" != "" ] ; then
>                             RutaPython="$AlternativaActual"
>                         fi
>                     done
>                 fi
>             fi
>             VersionPython="$(UnaPalabra () { echo $2; }; UnaPalabra 
> $($RutaPython --version))"
>             if [ "$(echo "$VersionPython" | grep -ie 
> "^$VersionDeseadaPython")" = "" ] ; then
>                 xmessage "ADVERTENCIA: Se necesita Python 
> $VersionDeseadaPython para que el programa funcione correctamente."
>             fi
>         fi
>         echo "\"$RutaPython\" \"$(which "$EjecutableLanzar")\""
>         "$RutaPython" "$(which "$EjecutableLanzar")"
>         Result=$?
>     else
>         xmessage "PROBLEMA: No se encuentra el interprete Python.
> SOLUCION: Pruebe a instalar el paquete \"python\"."
>         Result=1
>     fi
> else
>     xmessage "PROBLEMA: No se encuentra el programa $EjecutableLanzar"
>     Result=1
> fi
> exit $Result
>
>
> Al 07/02/11 13:04, En/na Francisco Javier Cuadrado ha escrit:
>> El día 7 de febrero de 2011 12:48, Narcis Garcia - GiLUG
>> <informatica en actiu.net>  escribió:
>>> ¿En cambio si que es de esperar que "env" se encuentre en /usr/bin en
>>> cualquier entorno GNU?
>>>
>> Aquí tienes una discusión de la lista «tutor» de python:
>> http://mail.python.org/pipermail/tutor/2007-June/054808.html
>>
>> En este mensaje[1] dicen (y cito):
>>
>> «[...] env is almost always located in /usr/bin/ so one need not worry
>> what is env is not present at /usr/bin) [...]»
>>
>> Lo que viene a decir (por alguien no sabe inglés) que: «env está casi
>> siempre ubicado en /usr/bin de modo que no hay que preocuparse por si
>> env no está presente en /usr/bin»
>>
>> Mi opinión es que es más probable que env esté instalado en un sistema
>> y esté en /usr/bin, que python esté instalado y que esté en el
>> directorio que tú pienses que está.
>>
>> [1] http://mail.python.org/pipermail/tutor/2007-June/054816.html
>>
>>> Por lo de la version, quizas vale la pena hacer un lanzador escrito 
>>> en Bash
>>> que busque si hay un "python2*" ejecutable.
>>>
>>>
>>> Al 07/02/11 12:38, En/na Jesús Espino ha escrit:
>>>> Si usas /usr/bin/python y el usuario tiene instalado python en /bin o
>>>> en /usr/local/bin, no funcionara si usas /usr/bin/env python eso queda
>>>> independizado.
>>>>
>>>> Un saludo.
>>>>
>>>> 2011/2/7 Narcis Garcia - GiLUG<informatica en actiu.net>:
>>>>> ¿Para que hacer intervenir a "env" si ya hay el ejecutable "python"?
>>>>>
>>>>>
>>>>> Al 07/02/11 12:11, En/na Jesús Espino ha escrit:
>>>>>> Para diferenciar entre python 3 y python 2, ahora mismo no sabría
>>>>>> decirte, pero en Ubuntu y supongo que en el resto de los Linux
>>>>>> funciona muy bien su usas #!/usr/bin/env python y si usas
>>>>>> #!/usr/bin/env python3 pues ejecutaria con python3. El comando env
>>>>>> escoge la versión que el usuario tenga instalada.
>>>>>>
>>>>>> Un saludo.
>>>>>>
>>>>>> 2011/2/7 Narcis Garcia - GiLUG<informatica en actiu.net>:
>>>>>>> Hola y gracias por leer mi consulta.
>>>>>>>
>>>>>>> Al escribir un programa en Python, que lo estoy intentando en 
>>>>>>> Python 2,
>>>>>>> como
>>>>>>> primera linea del fichero pongo:
>>>>>>> #!/usr/bin/python2
>>>>>>> Pero hay instalaciones en donde no esta el ejecutable "python2", 
>>>>>>> sino
>>>>>>> que
>>>>>>> hay el "python" a secas o subversiones como "python2.6":
>>>>>>> bash: miprograma.py: /usr/bin/python2: interprete erroneo: No 
>>>>>>> existe el
>>>>>>> fichero o el directorio
>>>>>>>
>>>>>>> Como me imagino que Python 3 no interpretara bien los programas
>>>>>>> escritos
>>>>>>> en
>>>>>>> Python 2, en el momento de extenderse Python 3 y establecerse como
>>>>>>> predeterminado en los sistemas, aquel programador que haya 
>>>>>>> especificado
>>>>>>> /usr/bin/python sin el "2" tendra problemas.
>>>>>>> Me imagino que en el pasado esto tambien ocurrio con Python 1.
>>>>>>>
>>>>>>> Si como primera linea especifico "python2.6" tendre problemas en
>>>>>>> sistemas
>>>>>>> que en su lugar tengan "python2.7" o "python2.5"
>>>>>>>
>>>>>>> ¿alguien encontro una solucion para correr sobre cualquier 
>>>>>>> subversion
>>>>>>> de
>>>>>>> Python 2.x?
>>>>>>> _______________________________________________
>>>>>>> Python-es mailing list
>>>>>>> Python-es en python.org
>>>>>>> http://mail.python.org/mailman/listinfo/python-es
>>>>>>> FAQ: http://python-es-faq.wikidot.com/
>>>>>>>
>>>>>> _______________________________________________
>>>>>> Python-es mailing list
>>>>>> Python-es en python.org
>>>>>> http://mail.python.org/mailman/listinfo/python-es
>>>>>> FAQ: http://python-es-faq.wikidot.com/
>>>>> _______________________________________________
>>>>> Python-es mailing list
>>>>> Python-es en python.org
>>>>> http://mail.python.org/mailman/listinfo/python-es
>>>>> FAQ: http://python-es-faq.wikidot.com/
>>>>>
>>>> _______________________________________________
>>>> Python-es mailing list
>>>> Python-es en python.org
>>>> http://mail.python.org/mailman/listinfo/python-es
>>>> FAQ: http://python-es-faq.wikidot.com/
>>> _______________________________________________
>>> Python-es mailing list
>>> Python-es en python.org
>>> http://mail.python.org/mailman/listinfo/python-es
>>> FAQ: http://python-es-faq.wikidot.com/
>>>
>>
>>
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/


Más información sobre la lista de distribución Python-es