Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Shebang line for Python 2.7

I have installed Python2.7 in my Linux Centos which comes with a default Python2.6 installation,

Default Python

[root@linuxhost PythonProjects]# python -V
Python 2.6.6

Default Python2.7

[root@linuxhost PythonProjects]# python2.7 -V
Python 2.7.3

Now I need to write programs based on python2.7 version...What would be the shebang line for python2.7

Also, how will I compile using python2.7.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Shebang will be:

#!/usr/bin/env python2.7

I'm not sure why you want to compile Python files (Python will do it automatically when you import them).

If you really want to:

python2.7 -m compileall .

This command will compile .py files in the current directory to .pyc:

over 4 years ago · Santiago Trujillo Relatório

0

I don think a sheebang line alone would do it.

You could try putting in

#! /usr/bin/env python2.7

though. - But the thing that really would be consistent for you would be to use virtual python environments through virtualenv.

Please, check http://www.virtualenv.org/en/latest/virtualenv.html - Otherwise you will risk having code running with the 2.7 Python but trying to load python 2.6 modules and libraries, and worse scenarios still.

Also, the recommendation for having two same-major-version Python in a system is to keep both in different prefixes, like the system one in /usr, and the other in /opt (/usr/local won't suffice for a clear separation).

over 4 years ago · Santiago Trujillo Relatório

0

You could change the shebang to #!/usr/bin/env python2.7.

Or you could use environment modules and let the shebang be #!/usr/bin/env python. The when you load the python 2.7 module (which can be your default), the script is run with python 2.7, and when you load the python 2.6 module, the script is run with python 2.6.

On this box I have python 2.6 and 2.7 installed. Depending on the module that is loaded, the selected version of python is run. Libraries, modules and packages are consistently loaded for the correct version.

$ cat t.py 
#!/bin/env python
import sys
print(sys.version)
$ ./t.py 
2.6.6 (r266:84292, Jul 10 2013, 22:48:45) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
$ module load python/2.7.3 
$ ./t.py 
2.7.3 (default, Nov  7 2012, 16:29:59) 
[GCC 4.7.2]
$ 

Or you could use virtualenv as @jsbueno suggests.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda