Reputation: 12395
I used python installer (downloaded from www.python.org) to install python3.8 & python 3.9. Is it possbile to switch them between different projects ? I don't think pyenv will work here (yet) because pyenv can only switch the versions installed by it. https://github.com/pyenv/pyenv/issues/1628 confirms this.
So for example, when run pyenv versions
on my machine
➤ pyenv versions
* system (set by /Users/qiulang/.pyenv/version)
3.4.0
3.5.3
3.6.10
The system version there is python3.9.
Most of my python scripts need 3.8 because I used pip3 install
the packages under 3.8.
I installed 3.9 to experience the latest feature but I don't won't 3.9 to be my default python3, otherwise I need to installed the packages all over again.
Now I can't find a way to do that so I had to change my script from
#! /usr/bin/env python3
to #! /usr/local/bin/python3.8
as a temporary solution.
Upvotes: 1
Views: 110
Reputation: 23079
I had the same question just a week or so ago. There's an extension for pyenv
called pyenv-register. I installed that and used it to register each of my Homebrew installed Python versions. This gives you a pyenv
version for each Python you register that looks something like system-3.9.0
.
After registering the Homebrew installed Python versions, I created symlinks in ~/.pyenv/versions
to create some simpler aliases for each of the versions I registered. Here's what that directory looks like on my system:
lrwxr-xr-x 1 steve staff 6 Jun 23 2019 2 -> 2.7.16
lrwxr-xr-x 1 steve staff 6 Jun 23 2019 2.7 -> 2.7.16
drwxr-xr-x 6 steve staff 192 Jun 23 2019 2.7.16
lrwxr-xr-x 1 steve staff 5 Jun 23 2019 3 -> 3.7.3
lrwxr-xr-x 1 steve staff 5 Jun 23 2019 3.7 -> 3.7.3
drwxr-xr-x 6 steve staff 192 Jun 23 2019 3.7.3
lrwxr-xr-x 1 steve staff 5 Nov 14 14:51 3.8 -> 3.8.6
lrwxr-xr-x 1 steve staff 12 Nov 14 14:51 3.8.6 -> system-3.8.6
lrwxr-xr-x 1 steve staff 5 Nov 14 14:51 3.9 -> 3.9.0
lrwxr-xr-x 1 steve staff 12 Nov 14 14:51 3.9.0 -> system-3.9.0
drwxr-xr-x 6 steve staff 192 Nov 14 14:48 system-3.8.6
drwxr-xr-x 6 steve staff 192 Nov 14 14:50 system-3.9.0
and here's what pyenv versions
gives me:
% pyenv versions
system
2
2.7
2.7.16
* 3 (set by /Users/steve/.pyenv/version)
3.7
3.7.3
3.8
3.8.6
3.9
3.9.0
system-3.8.6
system-3.9.0
This works great for me, having installed my new Pythons with Homebrew. I assume that it will work just as well for Python versions installed with a downloaded installer. I hope this helps you out!
Upvotes: 2