Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!