Skip to content

Commit

Permalink
Update install-and-upgrade.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCurrin authored Aug 9, 2024
1 parent 2ac94ae commit c584b78
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions cheatsheets/python/install/install-and-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ See more info in these gists:

Using `apt-get`.

### Latest
### Latest for your OS

```sh
$ sudo apt-get install -y python3
Expand All @@ -19,14 +19,14 @@ $ sudo apt-get install -y python3
### Target

```sh
$ sudo apt-get install -y python3.7
$ sudo apt-get install -y python3.12
```

### Non-standard

If the APT repositories don't support the old or new version you're after.
If the APT repositories don't support an old or new version you're after, add a custom repository as below.

Using [deadsnakes PPA](https://launchpad.net/%7Edeadsnakes/+archive/ubuntu/ppa) for Ubuntu.
Using [deadsnakes PPA](https://launchpad.net/%7Edeadsnakes/+archive/ubuntu/ppa) for Ubuntu:

```sh
$ sudo add-apt-repository ppa:deadsnakes/ppa
Expand All @@ -44,20 +44,35 @@ Note that upgrading Python with Homebrew causes all my virtual envs to break. Us

### Install

Using the [[email protected]](https://formulae.brew.sh/formula/[email protected]) formula.
Install the latest:

```sh
$ brew install python
```

Install target version e.g. [[email protected]](https://formulae.brew.sh/formula/[email protected]) formula.

```sh
$ brew install [email protected]
```

Or for latest:
See [Python Homebrew docs](https://docs.brew.sh/Homebrew-and-Python).

### Upgrade

Upgrade existing:

```sh
$ brew install python
$ brew upgrade python
```

Or install a target version and set it as the default using [Change default version][].

Or install a target version and uninstall the old versions, breaking any apps and virtual environments that use them.

### Upgrading
[Change default version]: {% link cheatsheets/python/install/change-default-version.md %}

#### My experience

I had 3 versions of PY3 installed.

Expand All @@ -79,7 +94,6 @@ [email protected]: stable 3.8.6 (bottled)

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.


```
==> [email protected]
Python has been installed as
Expand Down Expand Up @@ -112,11 +126,8 @@ For pkg-config to find [email protected] you may need to set:

Try this to sort out the linking:

```sh
```console
$ brew unlink python && brew link python
```

```
Unlinking /usr/local/Cellar/[email protected]/3.8.6... 2 symlinks removed
Linking /usr/local/Cellar/[email protected]/3.8.6...
Error: Could not symlink bin/pip3
Expand All @@ -133,7 +144,7 @@ To list all files that would be deleted:

Or

```sh
```console
$ brew unlink python
$ brew link [email protected]
Warning: [email protected] is keg-only and must be linked with --force
Expand All @@ -142,8 +153,7 @@ If you need to have this software first in your PATH instead consider running:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
```


```sh
```console
$ brew link [email protected] --force
Linking /usr/local/Cellar/[email protected]/3.9.0... 21 symlinks created

Expand All @@ -167,7 +177,7 @@ 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.

```sh
```console
$ brew uninstall [email protected]
Error: Refusing to uninstall /usr/local/Cellar/[email protected]/3.8.6
because it is required by ipython, libxml2 and libxmlsec1, which are currently installed.
Expand Down

0 comments on commit c584b78

Please sign in to comment.