How to run a program that is written in Python 3.5 through the terminal in mac os?

2 answers 2

1) Start the terminal
2) Navigate to the folder with the file by running the following command:

cd <ΠΏΡƒΡ‚ΡŒ/ΠΊ/запускаСмому/Ρ„Π°ΠΉΠ»Ρƒ/> 

3) Now run the file with the following command:

 python3 <имя_Ρ„Π°ΠΉΠ»Π°>.py 

4) Wait for the file to complete.
5) Close the terminal :)

PS "<>" do not write

PSS If necessary without python3 use aliases.

Unix aliases have the following syntax:
alias <псСвдоним> = '<команда>'
In your case, the team will look like this:
alias <имя Ρ„Π°ΠΉΠ»Π°> = 'python3 <имя Ρ„Π°ΠΉΠ»Π°>'

The nickname created in this way will work until the session is completed.
It is recommended that you use the ~ / .bash_aliases file to create permanent aliases in UNIX, but this file is not processed in Mac OS X. Therefore, you can add them to the ~ / .bash_profile file.


More information about aliases here: osxh.ru/terminal/command/alias

  • And without Python 3, you can somehow? - lalalala
  • Em. How are you going to run a program written in python3 without python3? Python is an interpreter, it executes the code right away, without compiling. If it’s very much like it, you can compile it via cx_freeze. - Sithell
  • I had to enter without 'python3' and not without an interpreter) wondered if it was possible to enter only the file name - lalalala
  • Use pseudonyms. Syntax: alias <псСвдоним> = '<ΠΊΠΎΠΌΠ°Π½Π΄Π°>' . It is recommended that you use the ~ / .bash_aliases file to create permanent aliases in UNIX, but this file is not processed in Mac OS X. Therefore, you can add them to the ~ / .bash_profile file. Read more here: osxh.ru/terminal/command/alias - Sithell

You go into the folder in which the file is located through the terminal and enter:

 python3 name_file.py 
  • and in the folder how to enter? and you can not open the file directly only by using the terminal as a program? - lalalala
  • Try to write more detailed answers. Explain what is the basis of your statement? - Nicolas Chabanovsky ♦
  • the ls command can be brought out - Vova Voloshyn
  • pwd you can know the path where you are now. The ls lists the files and folders in this directory. to switch to another directory, use the command cd 'folder_name' name without quotes. when you wake in the correct folder then the command: python3 file_name.py - Vova Voloshyn