Skip to content

Commit

Permalink
deploy: c584b78
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCurrin committed Aug 9, 2024
1 parent aadf793 commit fe11414
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 46 deletions.
67 changes: 39 additions & 28 deletions cheatsheets/python/install/install-and-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ <h2 id="linux">Linux</h2>

<p>Using <code class="language-plaintext highlighter-rouge">apt-get</code>.</p>

<h3 id="latest">Latest</h3>
<h3 id="latest-for-your-os">Latest for your OS</h3>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">sudo </span>apt-get <span class="nb">install</span> <span class="nt">-y</span> python3
</code></pre></div></div>

<h3 id="target">Target</h3>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">sudo </span>apt-get <span class="nb">install</span> <span class="nt">-y</span> python3.7
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">sudo </span>apt-get <span class="nb">install</span> <span class="nt">-y</span> python3.12
</code></pre></div></div>

<h3 id="non-standard">Non-standard</h3>

<p>If the APT repositories don’t support the old or new version you’re after.</p>
<p>If the APT repositories don’t support an old or new version you’re after, add a custom repository as below.</p>

<p>Using <a href="https://launchpad.net/%7Edeadsnakes/+archive/ubuntu/ppa">deadsnakes PPA</a> for Ubuntu.</p>
<p>Using <a href="https://launchpad.net/%7Edeadsnakes/+archive/ubuntu/ppa">deadsnakes PPA</a> for Ubuntu:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">sudo </span>add-apt-repository ppa:deadsnakes/ppa
<span class="nv">$ </span><span class="nb">sudo </span>apt-get <span class="nb">install</span> <span class="nt">-y</span> python3.7
Expand All @@ -208,17 +208,30 @@ <h2 id="macos">macOS</h2>

<h3 id="install">Install</h3>

<p>Using the <a href="https://formulae.brew.sh/formula/python@3.9">python@3.9</a> formula.</p>
<p>Install the latest:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">install </span>python
</code></pre></div></div>

<p>Install target version e.g. <a href="https://formulae.brew.sh/formula/python@3.9">python@3.9</a> formula.</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">install </span>python@3.9
</code></pre></div></div>

<p>Or for latest:</p>
<p>See <a href="https://docs.brew.sh/Homebrew-and-Python">Python Homebrew docs</a>.</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">install </span>python
<h3 id="upgrade">Upgrade</h3>

<p>Upgrade existing:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew upgrade python
</code></pre></div></div>

<h3 id="upgrading">Upgrading</h3>
<p>Or install a target version and set it as the default using <a href="/dev-cheatsheets/cheatsheets/python/install/change-default-version.html">Change default version</a>.</p>

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

<h4 id="my-experience">My experience</h4>

<p>I had 3 versions of PY3 installed.</p>

Expand Down Expand Up @@ -268,10 +281,8 @@ <h3 id="upgrading">Upgrading</h3>

<p>Try this to sort out the linking:</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">unlink </span>python <span class="o">&amp;&amp;</span> brew <span class="nb">link </span>python
</code></pre></div></div>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Unlinking /usr/local/Cellar/python@3.8/3.8.6... 2 symlinks removed
<div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gp">$</span><span class="w"> </span>brew <span class="nb">unlink </span>python <span class="o">&amp;&amp;</span> brew <span class="nb">link </span>python
<span class="go">Unlinking /usr/local/Cellar/python@3.8/3.8.6... 2 symlinks removed
Linking /usr/local/Cellar/python@3.8/3.8.6...
Error: Could not symlink bin/pip3
Target /usr/local/bin/pip3
Expand All @@ -283,24 +294,24 @@ <h3 id="upgrading">Upgrading</h3>

To list all files that would be deleted:
brew link --overwrite --dry-run python@3.8
</code></pre></div></div>
</span></code></pre></div></div>

<p>Or</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">unlink </span>python
<span class="nv">$ </span>brew <span class="nb">link </span>python@3.9
Warning: python@3.9 is keg-only and must be linked with <span class="nt">--force</span>
<div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gp">$</span><span class="w"> </span>brew <span class="nb">unlink </span>python
<span class="gp">$</span><span class="w"> </span>brew <span class="nb">link </span>python@3.9
<span class="go">Warning: python@3.9 is keg-only and must be linked with --force

If you need to have this software first <span class="k">in </span>your PATH instead consider running:
<span class="nb">echo</span> <span class="s1">'export PATH="/usr/local/opt/python@3.9/bin:$PATH"'</span> <span class="o">&gt;&gt;</span> ~/.zshrc
</code></pre></div></div>
If you need to have this software first in your PATH instead consider running:
</span><span class="gp"> echo 'export PATH="/usr/local/opt/python@3.9/bin:$</span>PATH<span class="s2">"' &gt;&gt; ~/.zshrc
</span></code></pre></div></div>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew <span class="nb">link </span>python@3.9 <span class="nt">--force</span>
Linking /usr/local/Cellar/python@3.9/3.9.0... 21 symlinks created
<div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gp">$</span><span class="w"> </span>brew <span class="nb">link </span>python@3.9 <span class="nt">--force</span>
<span class="go">Linking /usr/local/Cellar/python@3.9/3.9.0... 21 symlinks created

If you need to have this software first <span class="k">in </span>your PATH instead consider running:
<span class="nb">echo</span> <span class="s1">'export PATH="/usr/local/opt/python@3.9/bin:$PATH"'</span> <span class="o">&gt;&gt;</span> ~/.zshrc
</code></pre></div></div>
If you need to have this software first in your PATH instead consider running:
</span><span class="gp"> echo 'export PATH="/usr/local/opt/python@3.9/bin:$</span>PATH<span class="s2">"' &gt;&gt; ~/.zshrc
</span></code></pre></div></div>
<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>python3 <span class="nt">-V</span>
Python 3.7.3
</code></pre></div></div>
Expand All @@ -316,12 +327,12 @@ <h3 id="upgrading">Upgrading</h3>

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

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>brew uninstall python@3.8
Error: Refusing to uninstall /usr/local/Cellar/python@3.8/3.8.6
<div class="language-console highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gp">$</span><span class="w"> </span>brew uninstall python@3.8
<span class="go">Error: Refusing to uninstall /usr/local/Cellar/python@3.8/3.8.6
because it is required by ipython, libxml2 and libxmlsec1, which are currently installed.
You can override this and force removal with:
brew uninstall <span class="nt">--ignore-dependencies</span> python@3.8
</code></pre></div></div>
brew uninstall --ignore-dependencies python@3.8
</span></code></pre></div></div>

<p>Doing an install of Python 3.9 made it the default without having to update my <code class="language-plaintext highlighter-rouge">PATH</code>.</p>

Expand Down
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 [python@3.9](https://formulae.brew.sh/formula/python@3.9) formula.
Install the latest:

```sh
$ brew install python
```

Install target version e.g. [python@3.9](https://formulae.brew.sh/formula/python@3.9) formula.

```sh
$ brew install python@3.9
```

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 @@ python@3.8: 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.


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

Try this to sort out the linking:

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

```
Unlinking /usr/local/Cellar/python@3.8/3.8.6... 2 symlinks removed
Linking /usr/local/Cellar/python@3.8/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 python@3.9
Warning: python@3.9 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/python@3.9/bin:$PATH"' >> ~/.zshrc
```


```sh
```console
$ brew link python@3.9 --force
Linking /usr/local/Cellar/python@3.9/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 python@3.8
Error: Refusing to uninstall /usr/local/Cellar/python@3.8/3.8.6
because it is required by ipython, libxml2 and libxmlsec1, which are currently installed.
Expand Down
2 changes: 1 addition & 1 deletion feed.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.3">Jekyll</generator><link href="https://michaelcurrin.github.io/dev-cheatsheets/feed.xml" rel="self" type="application/atom+xml" /><link href="https://michaelcurrin.github.io/dev-cheatsheets/" rel="alternate" type="text/html" /><updated>2024-08-09T14:26:30+00:00</updated><id>https://michaelcurrin.github.io/dev-cheatsheets/feed.xml</id><title type="html">Dev Cheatsheets</title><subtitle>A collection of code snippets and CLI guides for quick and easy reference while coding</subtitle><author><name>Michael Currin</name></author></feed>
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.3.3">Jekyll</generator><link href="https://michaelcurrin.github.io/dev-cheatsheets/feed.xml" rel="self" type="application/atom+xml" /><link href="https://michaelcurrin.github.io/dev-cheatsheets/" rel="alternate" type="text/html" /><updated>2024-08-09T14:32:13+00:00</updated><id>https://michaelcurrin.github.io/dev-cheatsheets/feed.xml</id><title type="html">Dev Cheatsheets</title><subtitle>A collection of code snippets and CLI guides for quick and easy reference while coding</subtitle><author><name>Michael Currin</name></author></feed>

0 comments on commit fe11414

Please sign in to comment.