Link multiple Python versions #2776
-
|
I'd like to use multiple Python versions at the same time. I see that Homebrew has packages for Python ranging from 3.7 to 3.10. If I install one of those, I get symlinks to the installed binaries in Once one version has been linked, is it possible to link additional versions via only the specific version number so that I'd e.g. have symlinks at I've been doing this with MacPorts and would like to replicate my environment with Homebrew (if possible without additional package managers like pyenv). |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 21 replies
-
|
It's not currently possible, but I believe it is possible in principle if the various Python formulae were fixed up to support this. Dealing with the various executables ( This might require special handling of the contents of |
Beta Was this translation helpful? Give feedback.
-
|
The python makefile support the If you want to see how that might look, I have scripted this for myself as I wanted this at a time when it didn't look like HomeBrew would ever support something like this: https://gist.github.com/dwt/02d8a5c035e9cd3b1da8c55609d3f73b I'd be happy to help with the patches to homebrew - given the maintainers express interest in taking this in. |
Beta Was this translation helpful? Give feedback.
-
|
I honestly don't understand why would anyone like to have that kind of mess on his development machine. I defiantly would not. If you are suggesting this just because you are trying to avoid venv because of activate/deactivate, I am almost sure that you are not aware that you can use any python app from any venv without activating that venv. All my Python projects use venv, but I haven't use activate/deactivate for last few years. For example: will install requirements to python instance in ~/Python/Projects/MyProject/venv/ without activation and will properly run test.py without activation of venv first. |
Beta Was this translation helpful? Give feedback.
-
|
@dwt Absolutely, but my message was for @Feuermurmel. I didn't even read your messages before (but I did now). I agree with you to some extent, but you should be aware of few things.
If you check System/Library/Frameworks/Python.framework/ folder, you will see that all versions now point to 2.7. Also, as you already wrote, this approach is not used for python3 by default anymore (I am talking about macOS system installation at least). So I really do not see any real benefit of suggested changes. Maybe I am missing something obvious. Now let's get back to venv. As you probably know venv depends on the "base" python version that was used to create it. I am using many venvs with totally different python versions on my development machine. I just made extremely simple example to demonstrate few points. If you save this as pytest.sh and run it, you will get this result So, test37 was run using 3.7.12 and test38 was run using 3.8.12 even activate wasn't used, no new symlink was created nor any shell variable was changed. My point was that you need to use complete path to original python only once (when you creating a venv) and than you can use relative path to run your py scripts from shell. EDIT: my message was accidentally sent before I finished, so I had to edit it. EDIT2: I almost forgot. You can symlink 3.x versions and just use any of them as base interpreter (works both in shell and in pycharm) |
Beta Was this translation helpful? Give feedback.
-
|
Opened Homebrew/homebrew-core#107517 to try to implement this. |
Beta Was this translation helpful? Give feedback.
-
|
Hey all, I can certainly see the reasoning for this change, but in the event that we do not want to use python@3.10, and have a lot of scripts that run on cron jobs that require /usr/local/bin/python3 be python3.9, this breaks a lot of stuff. I discovered this the hard way when I upgraded something unrelated earlier today. Is there a way to force /usr/local/bin/python3 to point to an arbitrary version of python? Currently the only way to do this with Homebrew is to link python@3.10. The other way is to link python@3.9 and then make the symlinks the old-fashioned, hard way. |
Beta Was this translation helpful? Give feedback.
-
|
When I run:
brew install python@3.9
The default behavior should not be to install Python 3.10 and link all of the unversioned symlinks to the version of Python that I did not ask it to install. This breaks stuff, especially for dependencies that need to be installed via pip. The default behavior should be to install the version of Python that was asked for, no?
… On Aug 31, 2022, at 5:11 PM, Carlo Cabrera ***@***.***> wrote:
Why would you need to link ***@***.***? It is already linked, unless you previously unlinked it.
You can also add
$(brew --prefix ***@***.***)/libexec/bin
to your PATH if you wish to call python3.9 as python3.
—
Reply to this email directly, view it on GitHub <#2776 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ADUMFGYRDCJCBTEO4E3KDILV37YEFANCNFSM5L4QT5SQ>.
You are receiving this because you commented.
|
Beta Was this translation helpful? Give feedback.
It's not currently possible, but I believe it is possible in principle if the various Python formulae were fixed up to support this.
Dealing with the various executables (
python3,pip3, etc) is fairly straightforward, but there are some conflicts that will require a bit more work: