Contents
4 Answers
- Make sure the file is executable: chmod +x script.py.
- Use a shebang to let the kernel know what interpreter to use. The top line of the script should read: #!/usr/bin/python. This assumes that your script will run with the default python.
How do I run a Python script from command line?
Run your script
- Open Command line: Start menu -> Run and type cmd.
- Type: C:\python27\python.exe Z:\code\hw01\script.py.
- Or if your system is configured correctly, you can drag and drop your script from Explorer onto the Command Line window and press enter.
How do I run a Python file?
Part 2 Running a Python File
- Open Start. .
- Search for Command Prompt. Type in cmd to do so.
- Click. Command Prompt.
- Switch to your Python file’s directory. Type cd and a space, then type in the “Location” address for your Python file and press ↵ Enter .
- Enter the “python” command and your file’s name.
- Press ↵ Enter .