как запустить IDLE, среду разработки для Python, в Mac OS 10.7?
Я запускаю python 2.7.1. Я не могу понять, как запустить IDE IDE. Мне сказали, что он уже установлен с python, но я не могу найти его с помощью spotlight.
9 ответов
в фондовой установке Mac OS X python idle находится в /usr / bin, который не (легко) доступен из Finder и не индексируется Spotlight. Самый быстрый вариант-открыть утилиту терминала и ввести «idle» в командной строке. Для более Mac-подобного способа его открытия вам придется создать небольшое приложение или ярлык для запуска /usr/bin/idle для вас (упражнение, оставленное для читателя).
когда вы открываете новое окно терминала, просто введите
тогда вы увидите маленький значок ракеты появляются как холостые нагрузки
затем оболочка Python открывается для редактирования
один из способов запуска простоя из spotlight или значка в папке Applications-создать для него быструю автоматизацию. Как упоминалось другими комментаторами, это, вероятно, не нужно для Python 3, поскольку он автоматически создает ярлык, а в некоторых установленных вручную версиях есть инструменты для этого автоматически. Но если вы хотите свернуть свой собственный:
- вам нужно знать команду терминала, чтобы открыть свою версию IDLE. На моем Mac прямо сейчас (в начале 2016 года) работает python 2.7.10, это «idle2.7»
- С помощью spotlight или в папке Utilities откройте «Automator»
- выберите документ типа «приложение».
- убедитесь, что» действия » выбраны на серой панели в левом верхнем углу.
- в столбце действия найдите» запустить сценарий оболочки » и дважды щелкните его или перетащите в область рабочего процесса справа.
- введите команду терминала в появившемся поле параметры.
- сохранить вашу автоматизацию (я назвал мой «IDLE»и поместите его в папку приложений, чтобы сделать его легким).
- Теперь он доступен (как только spotlight индексирует его) через все обычные методы. Единственным побочным эффектом будет то, что во время работы в строке меню будет вращаться шестерня в области лотка рядом с часами. Это означает, что выполняется рабочий процесс автоматизации. Как только вы закроете холостой ход,он уйдет.
Как скачать и установить Python на Mac OC X
Это краткий туториал покажет вам, как правильно установить Python 3 на Mac OS X. Существует несколько способов установки Python 3, включая скачивание с [официального сайта Python] (https://www.python.org/downloads/), однако я настоятельно рекомендую вместо этого использовать менеджер пакетов, такой как Homebrew для управления всеми вашими зависимостями в будущем. Это сделает вашу жизнь намного проще.
Какая версия python установлена по умолчанию
Хотя Python 2 установлен по умолчанию на компьютерах Apple, Python 3 — нет. Вы можете проверить это, набрав в Терминале python —version и нажав return:
Чтобы проверить, установлен ли Python 3, попробуйте запустить команду python3 —version . Скорее всего, вы увидите сообщение об ошибке, но стоит проверить. Даже если у вас есть версия Python 3, мы обновим ее до самой последней версии, которая на данный момент в 2019 году 3.7.2.
Установка Xcode и Homebrew
Мы будем использовать менеджер пакетов Homebrew для установки Python 3 — это общая практика. Homebrew необходим пакет Xcode Apple, поэтому для его установки выполните следующую команду:
Нажимайте далее или подтвердить (Xcode — большая программа, ее установка может занять некоторое время).
Далее установите Homebrew:
Чтобы проверить правильность установки Homebrew, выполните следующую команду:
Установка Python 3 на MAC OC X
Чтобы скачать и установить последнюю версию Python, выполните следующую команду:
Подождите пока установятся все зависимости и сам python 3
Теперь давайте подтвердим, какая версия установилась:
Что бы писать код Python 3 из командной строки, введите python3:
Если вы хотите выйти, введите exit() и return или Ctrl-D (одновременно клавиши Control и D).
Что бы запустить оболочку Python 2, просто вводите python :
[Бонус] Первый код в IDLE python для новичков
Теперь Python 3 установлен на ваш Mac, пора приступить к конкретному написанию первого кода. В Python большинство команд основано на контекстных словах в английском языке. Если в C# потребовалось бы ввести команду Console.WriteLine , чтобы вывести запись на экран, в Python это простая команда print .
Я покажу 3 простые задачи, которые есть в каждом коде:
- вывод данных
- операция сложения
- использование условного оператора if
Для нашей первой задачи мы будем использовать IDLE. Это простой редактор кода, поставляется вместе с Python при его установке. Воспользуйтесь поиском и откройте IDLE.
Откроется окно, которое мы называем “оболочкой”. Там отображается результат выполнения кода, но писать код мы будем отдельно. Для этого нам нужно создать новый файл. Мы можем сделать это, нажав File > New File в верхнем меню. Откроется новый пустой файл.
Сохраните файл. Выберите File > Save As , затем сохраните его как helloworld.py . Обычно, в качестве первой программы используют вывод «Hello World» на экран.
Команда, которую мы собираемся использовать, является командой вывода данных в оболочку. Эта команда выглядит следующим образом. В скобках в кавычках находится текст, который мы выведем на экран.
После того, как вы ввели этот код в файл , выберите File > Save в меню, чтобы сохранить обновленную программу, а затем нажмите Run > Run Module из меню. Ваш вывод появится в окне оболочки. Это должно выглядеть примерно так.
Попробуйте распечатать разные фразы на экране, чтобы привыкнуть к коду.
Наша вторая задача — заставить Python считать за нас. Создайте новый файл Calculation.py. На этот раз мы выведем результат сложения двух чисел. Прибавим 9 к 8, для этого нам нужно ввести в наш новый файл команду print , которая выглядит следующим образом.
Как только вы это сделаете, нужно сохранить и затем запустить программу, нажав Run > Run Module . В оболочке появится результат вычислений, вот так:
Попробуйте различные вычисления, чтобы привыкнуть, помните, что вокруг чисел не нужны кавычки. Если вы еще не знакомы с операторами python, рекомендую прочить эту статью.
Наконец, мы создадим еще одну базовую программу, которая будет выводить результат в зависимости от входных данных, с помощью оператора if . Давайте снова откроем новый файл и выпишем следующий синтаксис:
Здесь мы объявляем переменную my_number равную 100, затем создаем конструкцию if-else , чтобы проверить, больше ли my_number числа 50. Если утверждение верно, мы получим «Это большое число», в противном случае мы увидим «Это небольшое число». ». Не забудьте сохранить и запустить программу, как вы это делали в предыдущих примерах.
Вы заметите, что программа печатает «Это большое число», потому что наш номер превышает 50. Попробуйте поменять номер и посмотрите, какой результат получите. Например, что выведет скрипт, если my_number = 50 ?
If you are using a Python from any current python.org Python installer for macOS (3.8.0+, 3.7.2+, 3.6.8, or 2.7.16+), no further action is needed to use IDLE or tkinter. A built-in version of Tcl/Tk 8.6 will be used.
If you are using macOS 10.6 or later, the Apple-supplied Tcl/Tk 8.5 has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, do not use the Apple-supplied Pythons. Instead, install and use a newer version of Python from python.org or a third-party distributor that supplies or links with a newer version of Tcl/Tk.
Python’s integrated development environment, IDLE, and the tkinter GUI toolkit it uses, depend on the Tk GUI toolkit which is not part of Python itself. For best results, it is important that the proper release of Tcl/Tk is installed on your machine. For recent Python installers for macOS downloadable from this website, here is a summary of current recommendations followed by more detailed information.
Python Release | Installer Variant | macOS Release | Recommended Tcl/Tk | Alternate Tcl/Tk | Not Recommended |
---|---|---|---|---|---|
3.8.5, 3.7.9, 2.7.18 | all | 10.9 to 10.15 | built-in 8.6.8 |
Tk On macOS
There are currently three major variants of Tk in common use on macOS:
Aqua Cocoa Tk A newer native implementation available as a universal 64-bit and 32-bit binary. This variant is the standard native macOS variant in Tk 8.6 and as of Tk 8.5.13. Aqua Cocoa support was backported to Tk 8.5 (prior to 8.5.13) and released by Apple starting with macOS 10.6 and by ActiveState starting with their 8.5.9.1 release. Aqua Carbon Tk Because it is implemented with older macOS Carbon interfaces, it is only available as a 32-bit binary (usually for Intel and PowerPC processors). Aqua Carbon Tk 8.4 is included with macOS releases 10.4 through 10.14 and is also available from ActiveState. Aqua Carbon variants of Tk 8.5 had been available as an ActiveState Community Download prior to ActiveTcl 8.5.9. As of 8.5.13, the Tk project no longer supports Carbon builds of Tk 8.5. 32-bit-only Python installers downloadable from this website for older Python releases were linked with Aqua Carbon Tk 8.4. X11 Tk The traditional platform-independent UNIX Tk implementation which requires an X11 server, such as the Apple X11.app available as an optional component in older macOS releases or from third-party distributors. 64-bit and 32-bit binaries can be built. While the Python installers downloadable from this website do not support X11 Tk, other distributors of Python for macOS may do so.
Tcl/Tk Releases
built-in 8.6.8
As of Python 3.7.0, 3.6.8, and 2.7.16, all current Python installers for macOS downloadable from python.org supply their own private copies of Tcl/Tk 8.6.8. They do not look for or use any third-party or system copies of Tcl/Tk. This is an Aqua Cocoa Tk.
ActiveTcl 8.5.18.0
ActiveState provides binary distributions of Tcl/Tk which are upward compatible with and generally more up-to-date than those provided by Apple in macOS releases. This version of Tcl/Tk includes fixes for some critical problems that you may encounter using tkinter or IDLE (see Apple 8.5.9 below). You can download an installer for this release from the ActiveState web site. Note that ActiveState Community Edition binaries are not open source and are covered by an ActiveState license. You should read the license before downloading to verify that your usage complies with its terms of use. As of Python 3.7.0, 3.6.8, and 2.7.16, no current Python installers for macOS downloadable from python.org make use of this or any other external version of Tcl/Tk.
This is an Aqua Cocoa Tk.
Apple 8.5.9
This release is included in macOS 10.7 through at least macOS 10.14. As of this writing, there are at least two known issues with Tk 8.5.9 that are present in Apple 8.5.9 Tk but fixed in more recent upstream 8.5 releases. The more serious problem is an immediate crash in Tk when entering a composition character, like Option-u on a US keyboard. (This problem is documented as Tk bug 2907388.) There is also the more general problem of input manager support for composite characters (Tk bug 3205153) which has also been fixed in more recent Tcl/Tk 8.5 releases. You can avoid these problems by using a current python.org installer or by using a third-party distribution of Python that does not use Apple 8.5.9 Tk. This is an Aqua Cocoa Tk.
Apple 8.5.7
This release is included in macOS 10.6. IDLE is known to hang or crash when used with the Apple 8.5.7 included in all versions of macOS 10.6.x. Because of this, we strongly recommend that you do not attempt to use Tkinter or IDLE with the Apple-supplied Python 2.6.1 in 10.6. Instead, install a newer version of Python that supports a newer version of Tk. This is an Aqua Cocoa Tk.
How Python Chooses Which Tk Library To Use
While Tcl and Tk are separate frameworks and libraries, they are closely related and are normally installed or updated simultaneously. You should not attempt to mix-and-match Tcl and Tk versions. References to a specific version of Tk assume the corresponding version of Tcl is installed as well.
The Python for macOS installers downloaded from this website dynamically link at runtime to Tcl/Tk macOS frameworks. The Tcl/Tk major version is determined when the installer is created and cannot be overridden. All current python.org installers for Python 3.7.x, 3.6.x, and 2.7.x link to their own built-in Tcl/Tk 8.6 frameworks and do not use external Tcl/Tk frameworks so the rest of this section only applies to non-current releases and, as such, no longer supported.
The Python 64-bit/32-bit macOS installers for Python 3.6.x and and 2.7.x dynamically link to Tcl/Tk 8.5 frameworks. The dynamically linking occurs when tkinter (Python 3) or Tkinter (Python 2) is first imported (specifically, the internal _tkinter C extension module). By default, the macOS dynamic linker looks first in /Library/Frameworks for Tcl and Tk frameworks with the proper major version. This is the standard location for third-party or built from source frameworks, including the ActiveTcl releases. If frameworks of the proper major version are not found there, the dynamic linker looks for the same version in /System/Library/Frameworks, the location for Apple-supplied frameworks shipped with macOS. (Note, you should normally not modify or delete files in /System/Library.)
As is common on macOS, the installed Pythons and the Tcl and Tk frameworks are built to run on multiple CPU architectures (universal binaries) and across multiple macOS levels (minimum deployment target). For Python to be able to dynamically link with a particular Tcl and Tk version, the available architectures in the Tcl/Tk frameworks must include the architecture that Python is running in and their minimum deployment target should be no greater than that of Python.
Revision history
- 2020-08-17 — updated for 3.7.9
- 2020-07-20 — updated for 3.8.5
- 2020-06-27 — updated for 3.7.8
- 2020-05-14 — updated for 3.8.3
- 2020-03-10 — updated for 3.8.2 and 3.7.7
- 2019-12-19 — updated for 3.8.1, 3.7.6, and 2.7.17
- 2019-10-15 — updated for 3.8.0, 3.7.5, and macOS 10.15
- 2019-07-08 — updated for 3.7.4; 3.6.x is now security-fix-only
- 2019-03-25 — updated for 3.7.3
- 2019-03-03 — updated for 2.7.16
- 2018-12-24 — updated for 3.7.2 and 3.6.8
- 2018-10-20 — updated for 3.7.1, 3.6.7, and macOS 10.14
- 2018-06-27 — updated for 3.7.0 and 3.6.6
- 2018-05-30 — updated for 3.7.0b5
- 2018-05-02 — updated for 3.7.0b4 and 2.7.15; removed 32-bit-only refs
- 2018-03-29 — updated for 3.7.0b3 and 3.6.5
- 2018-02-28 — updated for 3.7.0b2
- 2018-01-31 — updated for 3.7.0b1 and 3.6.4
- 2017-10-03 — updated for 3.6.3 and macOS 10.13
- 2017-09-16 — updated for 2.7.14; removed 3.5.x
- 2017-07-17 — updated for 3.6.2
- 2017-03-21 — updated for 3.6.1 and (belatedly) 3.5.3
- 2016-12-23 — updated for 3.6.0
- 2016-12-17 — updated for 2.7.13
- 2016-09-23 — updated for macOS 10.12
- 2016-07-31 — updated for 3.5.2 and 2.7.12; removed 3.4.x
- 2015-12-20 — updated for 3.4.4
- 2015-12-06 — updated for 3.5.1, 2.7.11, and macOS 10.11
- 2015-09-13 — updated for 3.5.0
- 2015-05-23 — updated for 2.7.10 and ActiveTcl 8.5.18.0
- 2015-02-23 — updated for 3.4.3
- 2014-12-10 — updated for 2.7.9 and ActiveTcl 8.5.17.0
- 2014-10-16 — updated for macOS 10.10
- 2014-10-06 — updated for 3.4.2 and ActiveTcl 8.5.16.0
- 2014-09-22 — updated for 3.4.2rc1
- 2014-07-01 — updated for 2.7.8
- 2014-06-01 — updated for 2.7.7; removed 2.7.6 and 3.3.5
- 2014-05-18 — updated for 3.4.1 and 2.7.7rc1
- 2014-03-16 — updated for 3.4.0 and 3.3.5
- 2014-02-10 — updated for 3.3.4 and 3.4.0rc1
- 2014-01-05 — updated for 3.4.0b2
- 2013-11-24 — clarify that the ActiveState website still refers to 8.5.15.0
- 2013-11-24 — removed built-in for 3.4.0b1, removed 3.3.2 and 2.7.5
- 2013-11-10 — ActiveTcl 8.5.15.1; removed built-in for 3.3.3rc2 and 2.7.6.
- 2013-10-27 — updated for 3.3.3rc1 and 2.7.6rc1 and their built-in 8.5.15.
- 2013-10-24 — updated for macOS 10.9 and ActiveTcl 8.5.15, removed 3.2.5.
- 2013-10-20 — updated for 3.4.0a4 and its built-in 8.5.15.
- 2013-09-29 — updated for 3.4.0a3
- 2013-09-09 — updated for 3.4.0a2 and its built-in 8.5.14.
- 2013-08-03 — updated for 3.4.0a1 and ActiveTcl 8.4.20
- 2013-05-18 — updated for ActiveTcl 8.5.14
- 2013-05-15 — updated for 3.3.2, 2.7.5, and 3.2.5
- 2013-04-06 — updated for 3.3.1, 2.7.4, and 3.2.4
- 2012-12-26 — updated for ActiveTcl 8.5.13 and Issue 15853 patch installer
- 2012-09-29 — updated for 3.3.0 final and reverted to ActiveTcl 8.5.11.1
- 2012-08-02 — updated for ActiveTcl 8.5.12
- 2012-07-28 — updated for macOS 10.8
- 2012-04-11 — updated for 3.2.3 final and 2.7.3 final
- 2012-03-18 — updated for 3.2.3rc2 and 2.7.3rc2
- 2012-03-04 — updated for ActiveTcl 8.5.11.1, 3.2.3rc1, 2.7.3rc1, removed 3.1.4
- 2011-11-12 — updated for ActiveTcl 8.5.11
- 2011-09-04 — updated for 3.2.2 final
- 2011-07-21 — updated for macOS 10.7 and ActiveTcl 8.5.10.1
- 2011-07-09 — updated for 3.2.1 final and ActiveTcl 8.5.10
- 2011-06-12 — updated for 2.7.2 final and 3.1.4 final
- 2011-05-30 — updated for 3.2.1rc, 2.7.2rc, and 3.1.4rc
- 2011-03-08 — add warnings and include details on how Python links with Tcl/Tk releases
- 2011-02-20 — updated for 3.2 final
- 2011-01-31 draft 1 — preliminary info for 3.2rc2
- 2011-01-14 draft 0
The PSF
The Python Software Foundation is the organization behind Python. Become a member of the PSF and help advance the software and our mission.