Linux and Python

Source: Internet
Author: User
Tags python script

Linux is generally loaded with Python, but the version does not have to be viewed by itself, and if the version is too low, it needs to be re-installed. Look at the Python version method and enter Python directly at the command line, which will go to the Python command line and display the Python version.

How to exit the Python command line, enter exit ()

Sometimes we need to see where Python is installed to install third-party libraries, and Linux can enter Python cmd first, then enter

Import Sys
Print Sys.path To print all Python paths. How to run a well-written Python script in Linux:There are two ways of doing this:
1. Execute directly using Python xxxx.py. Where python can be written as the absolute path to Python. Query using which python (on my CentOS, the query result for the which Python command is/usr/bin/python).
2, in the head of the file (first line) write #!/usr/bin/python2.7, this place uses the absolute path of Python, is the above with which Python query results. Then you can use it outside./xxx.py executed.

Because in Linux, Python shell These programs are normal text format, need a program to explain to execute it. Either call the time specified (mode 1), or specify in the file header (mode 2).

Linux and Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.