In a Unix-like environment, we always need to invoke the Python interpreter when we write a Python script, usually in the following two ways:
| 1 |
#!/usr/bin/python |
| 2 |
#!/usr/bin/env python |
So what's the difference between the two methods of invoking the Python interpreter?
In fact, both of these formulations are right, where #!/usr/bin/python directly tells the operating system to execute this script time, go to the/usr/bin directory to find the Python interpreter. The #!/usr/bin/env python format is designed to accommodate Python's operating system, which is not installed by default in the/usr/bin directory, and when the system reads this type of reference, it looks for the Python installation path in the env settings. Then follow the Python interpreter under the installation path in Env to complete the script operation.
As a result, we should be accustomed to using the second approach when writing scripts so that our scripts or programs can be unblocked in a different UNIX environment for the Python installation directory.
This article is from "Life Beyond" blog, please be sure to keep this source http://cnlinux.blog.51cto.com/6112794/1587973
UNIX class environment calls Python interpreter