'qual python' e 'echo PYTHONPATH' fornece diretórios diferentes, o que isso significa?

1

Estou usando o Ubuntu 16.04 com o python 2.7. Eu estou tentando executar python de um diretório diferente daquele dado por

which python

Para este fim, eu coloquei

PYTHONPATH=$PYTHONPATH:/home/myname/pybombs/lib/python2.7/dist-packages/

no meu arquivo bashrc. Agora, which python retorna /usr/bin/python e echo PYTHONPATH retorna :/home/myname/pybombs/lib/python2.7/dist-packages/ .

Eles não deviam retornar os mesmos diretórios?

    
por Usama Saeed 01.08.2017 / 15:25

1 resposta

0

De man python :

   PYTHONPATH
          Augments  the  default search path for module files.  The format
          is the same as the shell's $PATH: one or  more  directory  path‐
          names   separated   by  colons.   Non-existent  directories  are
          silently ignored.   The  default  search  path  is  installation
          dependent,  but  generally begins with ${prefix}/lib/python<ver‐
          sion> (see PYTHONHOME above).  The default search path is always
          appended  to  $PYTHONPATH.   If  a script argument is given, the
          directory containing the script is inserted in the path in front
          of  $PYTHONPATH.  The search path can be manipulated from within
          a Python program as the variable sys.path.

A variável $PYTHONPATH apenas especifica locais adicionais dos quais você pode importar módulos. Não tem nada a ver com a localização do executável do interpretador Python que você obtém como saída de which python .

    
por Byte Commander 01.08.2017 / 15:33