Compiling Python

前端 未结 8 770
故里飘歌
故里飘歌 2020-12-29 17:59

How can I compile and run a python file (*.py extension)?

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 18:48

    On most Unix-like systems, you can use the shebang to tell the operating system which interpreter should be called. You simply put

    #!/path/to/python 
    

    in the first line of your file, where of course you have to replace "/path/to/" with the path you have on your system. In most cases this would be "/usr/bin/python" or "/usr/local/bin/python". On unix systems you could also look for the path with

    "#!usr/bin/env python" 
    

    or invoke the command

    which python
    

    to find the path. You can then run your program with the command

    ./yourprogram.py
    

    If it tells you that you do not have permission to do so, you have to use the command

    chmod a+x yourprogram.py
    

提交回复
热议问题