Посмотреть версию python mac os

How to Check Your Python Version

Chances are you have heard about Python 2 and Python 3. Although they are two versions of the same language, they have different syntax; code written in Python 3 might not work in Python 2. So, let’s discover how you can check your Python version on the command line and in the script on Windows, macOS, and Linux systems.

Python is one of the most popular programming languages. With its simple syntax, high productivity, and amazing open-source libraries, Python can be used for just about anything.

However, you might have seen that some people use Python 2, while others prefer Python 3. The difference between these two versions is quite significant – it’s not just about fixing some bugs and adding a few new features. If the application is written in Python 2, you may not be able to run it using Python 3.

So, you should definitely know the version of Python installed on your computer. Let’s see how you can check the Python version. We’ll start with the command line.

Check Python Version: Command Line

You can easily check your Python version on the command line/terminal/shell. Let’s first recall how we can access the command line in different operating systems.

Читайте также:  Свой механизм сессий php

Windows

macOS

Linux

Then, for any of the operations systems above, you simply type python —version OR python -V, on the command line and press Enter . You’ll get a result like this:

python --version Python 3.8.3 python -V Python 3.8.3

Depending on your Python distribution, you may get more information in the result set. However, the number next to Python is the version number, which is what we are looking for. In this case, the full version number is 3.8.3.

Usually, we are interested in the major version – Python 2 or Python 3. This is indicated by the first number of the full version number. This number is 3 in our case, which means that we have Python 3 installed on our computer.

Starting from Python 3.6, you can also use python -VV (this is two Vs, not a W) to get more detailed information about your Python version:

python -VV Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]

Check Python Version: Script

Sometimes you may want to check the version of Python when you are coding an application (i.e. inside the script). This is especially useful when you have multiple Python versions installed on your computer. To check which Python version is running, you can use either the sys or the platform module. The script will be the same for Windows, macOS, and Linux.

To check the Python version using the sys module, write:

import sys print (sys.version)
# 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]

To check the Python version using the platform module, use the following code:

import platform print(platform.python_version())

The output will be as follows:

Both code snippets output the Python version in the string format. If necessary, you can also get the version number in the tuple format. The tuple will contain five components: major, minor, micro, release level, and serial:

print (sys.version_info) # sys.version_info(major=3, minor=8, micro=3, releaselevel='final', serial=0)

Of course, you can easily obtain the individual components of this tuple using an index (e.g. sys.version_info[0] ) or a name (e.g. sys.version_info.major ).

Pretty simple, right? No wonder Python is so popular.

Python 2 or Python 3?

Now we know how to check the Python version. But what’s the difference between the two versions?

Python 2 is an older version that was actively used in software development and IT operations (DevOps). However, it is no longer under development and has been discontinued starting from January 1, 2020. This implies that any bugs or security problems discovered in Python 2 are no longer being addressed by Python developers. Python’s volunteer developers advise that people using Python 2 move to Python 3 as soon as possible.

Python 3 was first introduced in 2008. It’s syntax and behavior is quite different from Python 2, but it’s generally believed that Python 3 is simpler and easier to understand.

As Python 2 is no longer supported, you should definitely choose Python 3 if you are writing a new application or just starting to learn Python. The only reason to learn Python 2 is if your company’s code is written in Python 2 and you need to work with it. This shouldn’t be often the case, especially once Python 2 has been discontinued for a while.

Time to Practice Python!

Do you want to learn Python 3? Join the track Learning Programming with Python on LearnPython.com, where you will be introduced to the fundamentals of programming – not just in theory but with over 400 interactive coding challenges.

The track starts with Python Basics: Part 1, a course that teaches students how to create the simplest Python applications. This course (and the track itself) are aimed at students with no prior IT background. If you are already familiar with Python’s basics, join one of the advanced courses on LearnPython.com and learn how to work with strings, JSON files, and CSV files in Python.

Professionals across different industries enjoy the benefits of this simple and effective programming language. You can join them very soon! It doesn’t take much time to become proficient in Python, especially if you plan your studying activities appropriately.

Thanks for reading, and happy learning!

Источник

Как проверить версию Python на Mac и Windows

В данном руководстве рассмотрим, как проверить версию Python на Mac и Windows.

Проверка версии Python на Mac

Чтобы проверить версию Python на Mac, выполните следующие действия:

  1. Откройте терминал для Mac.
  2. Введите команду Python –version.
  3. Выполните ее, и она вернет установленную версию Python.

Как проверить версию Python на Mac

Проверка версии Python в Windows

Чтобы проверить версию Python в Windows:

  1. Откройте приложение командной строки(CMD) для Windows.
  2. Введите команду Python –version.
  3. Выполните ее, и она вернет установленную версию Python.

Если вы введете то же самое в оболочке Windows или в командной строке, вы получите установленную версию Python.

Если версия Python не работает в Linux или Windows, вы также можете написать одну из следующих команд.

Установка Python, его обновление, установка пакетов и стороннего программного обеспечения, такого как Anaconda, а также установка и обновление pip — одни из наиболее часто используемых операций, которые пользователи выполняют в своей системе.

Узнать версию Python с помощью скрипта

Вы можете проверить версию Python с помощью скрипта, импортировав модуль sys и используя выражение sys.version, он возвращает установленную версию Python в вашей системе.

Источник

Какая версия Python находится на моем Mac?

в редакторе PyCharm интерпретатор настроек по умолчанию показывает:

У вас может быть несколько версий Python в вашей macOS.

Вы можете проверить это с помощью команды command , type или which , например:

which -a python python2 python2.7 python3 python3.6 

Или введите python в Терминале и несколько раз нажмите Tab для автоматического завершения, что эквивалентно:

По умолчанию команды python / pip указывают на первый двоичный файл, найденный в переменной среды PATH , в зависимости от того, что фактически установлено. Поэтому, перед установкой пакетов Python с Homebrew, Python по умолчанию устанавливается в /usr/bin , который поставляется вместе с вашей MacOS (например, Python 2.7.10 в High Sierra). Любые версии, найденные в /usr/local (например, /usr/local/bin ), предоставляются внешними пакетами.

Обычно рекомендуется, чтобы при работе с несколькими версиями для Python 2 вы могли использовать команду python2 / pip2 , соответственно, для Python 3 вы можете использовать python3 / pip3 , но это зависит от вашей конфигурации, какие команды доступны.

Также стоит отметить, что после выпуска Homebrew 1.5. 0+ (19 января 2018 года) формула python была обновлена до Python 3.x, а формула python@2 будет быть добавленным для установки Python 2.7. Ранее формула python указывала на Python 2.

Например, если вы установили другую версию через Homebrew, попробуйте следующую команду:

он покажет вам все файлы Python, установленные вместе с пакетом.

В качестве альтернативы вы можете использовать команду apropos или locate python , чтобы найти больше файлов, связанных с Python.

Чтобы проверить все переменные среды, связанные с Python, выполните:

Для решения ваших проблем:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist 

Чтобы проверить третью версию, мы можем использовать python3 —version

Используйте команду ниже, чтобы увидеть все установки python:

Используйте which command . Он покажет вам путь

Версия в /System/Library/Frameworks/Python.framework установлена ​​Apple и используется системой. Это версия 3.3 в вашем случае. Вы можете получить доступ к этому интерпретатору Python и использовать его, но вы не должны пытаться его удалить, и это может быть не тот, который появляется при вводе “Python” в терминале или щелкните значок, чтобы запустить его.

В какой-то момент вы должны установить другую версию Python (2.7), и теперь это тот, который запускается по умолчанию.

Как указывали другие ответы, вы можете использовать команду which python на своем терминале, чтобы найти путь к этой другой установке.

Источник

What version of Python is on my Mac?

in PyCharm editor, the default settings interpreter shows:

I did : sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist but when I do locate python I always get the same WARNING.

6 Answers 6

You could have multiple Python versions on your macOS.

You may check that by command , type or which command, like:

which -a python python2 python2.7 python3 python3.6 

Or type python in Terminal and hit Tab few times for auto completion, which is equivalent to:

By default python / pip commands points to the first binary found in PATH environment variable depending what’s actually installed. So before installing Python packages with Homebrew, the default Python is installed in /usr/bin which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/local (such as /usr/local/bin ) are provided by external packages.

It is generally advised, that when working with multiple versions, for Python 2 you may use python2 / pip2 command, respectively for Python 3 you can use python3 / pip3 , but it depends on your configuration which commands are available.

It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the python formula has been upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7. Before, python formula was pointing to Python 2.

For instance, if you’ve installed different version via Homebrew, try the following command:

it’ll show you all Python files installed with the package.

Alternatively you may use apropos or locate python command to locate more Python related files.

To check any environment variables related to Python, run:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist 

Источник

Оцените статью