Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shebang line for Python 2.7

Tags:

python

linux

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.

like image 861
user1050619 Avatar asked Jan 17 '14 15:01

user1050619


People also ask

What is shebang line in Python?

#!/usr/bin/env python """ The first line in this file is the "shebang" line. When you execute a file from the shell, the shell tries to run the file using the command specified on the shebang line. The ! is called the "bang". The # is not called the "she", so sometimes the "shebang" line is also called the "hashbang".

What is #!/ Usr bin python3?

#!/usr/bin/python3 is a shebang line. A shebang line defines where the interpreter is located. In this case, the python3 interpreter is located in /usr/bin/python3 . A shebang line could also be a bash , ruby , perl or any other scripting languages' interpreter, for example: #!/bin/bash .

Does usr bin env need Python?

Just as a tip, you should always do #!/usr/bin/env python2 or #!/usr/bin/env python3. You should always make your Python scripts use a specific version of the interpreter rather than putting just 'python'.


1 Answers

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:

like image 180
Nigel Tufnel Avatar answered Oct 19 '22 05:10

Nigel Tufnel