Как обновить python через консоль
Перейти к содержимому

Как обновить python через консоль

  • автор:

Install and upgrade Python

If the APT repositories don’t support the old or new version you’re after.

macOS

Note that upgrading Python with Homebrew causes all my virtual envs to break. Using Pyenv is safer.

Install

Using the python@3.9 formula.

Upgrading

I had 3 versions of PY3 installed.

The system default is Python3.7.

And Python 3.8 was known by Brew.

Python 3.9 got installed because sphinx-doc has it as a dependency, but it did not replace the existing one. See notes from the output.

Try this to sort out the linking:

Then you can add this to PATH — /usr/local/opt/python@3 .

Also I can’t just delete the old one as it is used by other Brew packages.

Doing an install of Python 3.9 made it the default without having to update my PATH .

And /usr/local/bin/python3 links to ../Cellar/python@3.9/3.9.0/bin/python3 now.

Dev Cheatsheets

  • Michael Currin

A collection of code snippets and CLI guides for quick and easy reference while coding

How to Upgrade Python Version?

Python is a high-level , open-source , and object-oriented popular programming language used to create and design websites and software, and build machine learning applications. Alongside the once-a-year update that includes new features, and bug-fix, Python releases minor updates every few months. Since every new release comes with better functionality and features, it is vital to know how to upgrade the Python version. This article illustrates the different procedures to upgrade the Python version in the major operating systems — Windows , macOS , and Linux .

Upgrade Python Version on Windows

Using Python Installer

To update Python in Windows using the Python installer follow the mentioned steps.

    Step — 1 :
    At the initial step, check whether an update is required. To find out the existing version, use the following command : python -V

Using Chocolatey Package Manager

Chocolatey packages encapsulate everything required to manage a particular piece of software into one deployment artifact by wrapping installers, executables, zips, and scripts into a compiled package file. It can also upgrade the version of Python in Windows.

  • Step — 1 :
    Press Window+X to open the Power User menu. From the menu click on “Windows Terminal(Admin)” to open Windows PowerShell.
  • Step — 2 :
    Use the following command to install the Chocolatey package manager.

Upgrade Python Version on Linux

  • Step — 1 :
    At the initial step, check whether an update is required. To check the existing version open the Terminal by pressing Ctrl+Alt+T and type the following command : python -V or python —version — You should get a similar output as shown below.

Upgrade Python Version on Mac

  • Step — 1 :
    At the initial step, check the current version of Python on your machine to see whether an update is required or not. To check the existing version using the following command : python —version
  • Step — 2 :
    Since a Mac can support multiple versions of Python, you can update it by clicking on this link and downloading the installer. After downloading, run the file to complete the installation.
  • Step — 3 :
    To confirm if the changes have taken effect, recheck the version of Python. python3 —version

1. Which command checks the current version of Python in Windows, Linux, and macOS ?

The command used to check the latest version of python on a machine is

  • Windows : python —version or python -V
  • Linux : python —version or python -V
  • macOS : python —version

2. Why is it important to upgrade the Python version ?

Every new version of Python introduces developers to new features, better performance, new modules, additional functionalities, improvements in existing features, and removal of old unnecessary items and bugs. Thus, it is advised to keep Python upgraded to the latest version for smooth coding.

Get or update Python 3 on your computer

Anthony N. Carrillo

This is the fastest way to get python on your computer that I know of. And while there are many ways I suggest you use Anaconda. One of the best parts is that Anaconda offers installers for all OSs available. And since Python 2 is going to be killed off around 2020 by Python 3. It is best to get the 3.7 version installed.

1 — Download the installers for Windows, Mac, Linux. Although like anything else dealing with Linux I assume you already know all of this.

2 — Click through all of the default settings by clicking the “Continue” or “Install” buttons. While you can change the install settings on this page you should still select “install for me only” setting.

(I assume you are using YOUR computer, NOT a school or work one)

3 — Restart your computer.

And there you are. You should have python on your computer now. But first, read the next sections to make sure you did it right.

Where is the terminal?

If you are unaware of what the terminal is please follow the instructions from learn python the hard way to find out how to get to your terminal on your computer. No matter what OS it is.

To make sure you have the correct Python version

Go to the terminal (don’t type the ‘$’ sign EVER).

1 — In your terminal type $ python —version

You should get back something like Python 2.7.5

2 — If you get back version 2.whatever check for version 3

In your terminal type $ python3 —version

You should get back Python 3.7.0

If you got 3.7. whatever, YAY you did it.

UPDATE python 3

Use the Terminal for the following steps.

If you are in an environment with Python version 3. whatever, the following command updates Python to the latest version in the 3.whatever branch:

(bear in mind that it will take some time)

❌ But if that returns something like:

OR … (if the above fails the next command will do it)

✅ Now that you have done that you should finally see the following.

�� CONGRATS you finished the UPGRADE! ��

And you did not upgrade to the newest available anaconda 3 then try the next step.

The NEWEST Python 3 is 3.8 HOWEVER …
The installer is only up to 3.7 at the time of this writing. But that is OK for now don’t worry about it.

Congrats reader!
I hope that this short article helped you.
Welcome to a new world of possibilities.

How to update Python version in Terminal?

I’ve updated my version of Python to 3.11, but Terminal is printing different versions, depending on what command I enter.

Entering python3 —version prints Python 3.9.13 .

Entering python —version prints Python 3.9.6 .

When I go to the actual Python framework, I can see that 3.11 is installed and is the current version, per the shortcut there. There are multiple versions of Python—Python 3.7, 3.8, etc.—there; perhaps this is the issue.

I’ve looked into uninstalling some or all versions of Python, but I worry that will just make it worse—I’m not the most experienced programmer.

I’ve also tried adding an alias to the .zshrc file per other posts, but it didn’t work. I did save the file correctly, for what it’s worth. Any advice is appreciated.

macOS Ventura 13.0

Fix: I created a new user on my computer, which isn’t a true fix, but it allowed me to bypass this issue (messy PATH) with relative ease.

3 Answers 3

A terminal in a unix-based OS (including Darwin / MacOS and Linux) will search for the command you have typed in several places, in order, and the first match found will stop the search from finding other possible commands with the same name.

To simplify the answer, I’ll limit this to the bash shell as I don’t use ZSH, but I think the answer should be similar in both shells.

After you type in a line of input and hit enter, your shell will modify its input so that it expands variable interpolations and such things and then will take the first token (first "word") and search for that word as a command name.

Commands can be found in several places, from builtin commands, to aliases, to shell functions and if the command can’t be found there, the shell will begin looking at specific locations in your filesystem to look for files that are named the same as your command. The first match wins, so if you have several pythons in your PATH, the first one will be the one that is selected.

The set of locations in your filesystem the shell will look for the command is stored in an environment variable called PATH in the shell and is generally available to view and set.

to see what your path is:

or. for slightly easier reading:

which python will let you see what python version your shell is finding first in the PATH and type python will let you know if for some reason you have a function or alias named python that happens to overshadow your filesystem python executables.

Also, bash maintains an internal hash table of where it has previously found commands. So if you type python and bash finds it in /usr/bin/python, then it will remember that for the rest of the session. If you’d like it to look again, because perhaps you have installed a new python you expect it to find first, you can type hash -r to reset the hash table to a blank new one.

All that being said, if you are starting to develop in Python, you’re going to need to handle different versions of Python.

To start down that road, check out:

I recommend asdf as it can work for many things, not just python. Also, you’ll probably want a decent dependency manager sooner rather than later for your project, so I’d check out poetry and pipenv:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *