Method for linux to run py files directly

  • 2021-06-28 14:45:30
  • OfStack

1. Create the file first (cd to the directory you want to place)

touch myTest.py

2. Edit myTest.py

vi myTest.py

Add content to it

#!/usr/bin/env python

Then add the code you need to add

print('hello, world!')

Then enter command mode:: wq Save Exit vi

3. Change the permissions of myTest.py, if necessary, mainly for testing purposes, set 777

chmod 777 myTest.py

4. It is possible to run myTest.py directly in the current directory (similar to exe in windows)

./myTest.py


Related articles: