How to not update homebrew automatically when brew install some packages? - python

I installed python3 with homebrew on my Mac. However, the latest Python3.6 cannot work well with some packages, so I decide to roll back to the 3.5.2.
Since homebrew/versions has been deprecated,I checkout the commit in the directory: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
git log python3.rb
There
commit ec545d45d4512ace3570782283df4ecda6bb0044
Author: BrewTestBot <brew-test-bot#googlegroups.com>
Date: Tue Oct 11 06:42:06 2016 +0100
python3: update 3.5.2_3 bottle.
Then
git chekcout ec545
brew install python3
However, it seems that homebrew update itself automatically I run $brew install [Formula]
➜ Formula git:(ec545d4) brew install python3
Updating Homebrew...
How to not update homebrew automatically when brew install some packages?
Or how to install python 3.5.2 with homebrew?

Answer for the first question, How to not update homebrew automatically when brew install some packages?
hack code solution:
vim /usr/local/Homebrew/Library/Homebrew/brew.sh
Add return after line
update-preinstall() {
to:
update-preinstall() {
return
environment variable solution:
export HOMEBREW_NO_AUTO_UPDATE=1
or
export HOMEBREW_AUTO_UPDATING=0
or
export HOMEBREW_UPDATE_PREINSTALL=0
if U will always work, add it to .bash_profile

$ brew tap derekkwok/python or (zoidbergwill/python)
$ brew versions python
$ brew install python35
If you have already installed the older version of the formula you can simply switch the symlinks to reference it using a brew command.
brew switch python 3.5.2
If you want to keep a certain version and stop it from being updated ,you can pin a formula.
brew pin python
Also you can try this Python Version Management pyenv.
brew install pyenv
pyenv install 3.5.2
By the way,you can see homebrew-install-specific-version-of-formula to learn more.

Related

env: python3.9: No such file or directory

I have some python code formatters as git pre-commit hook and I have changed my python version as
brew list | grep python
python#3.7
python#3.9
brew unlink python#3.7
brew unlink python#3.9
brew link python#3.7
python -V
Python 3.7.9
and know seems something get broken and on git commit I get env: python3.9: No such file or directory, so what is env? and how I can edit it to use python#3.7?
In .git/hooks/pre-commit I have
#!/usr/bin/env python3.9
and running pre-commit install fixed it to #!/usr/bin/env python3.7
Even though #mrgloom answer pointed me in the right direction, it wasn't good enough to solve my situation.
This error just happened to me after I upgraded from Ubuntu 21.10 to 22.04. It clearly looks like the installed Python version isn't Python 3.9 anymore. So I quickly checked that right now I have 3.10.
Simply editing the .git/hooks/pre-commit with Python3.10 wasn't enough.
What worked for me was reinstall pre-commit: https://pre-commit.com/#install
So, you can either run pip install pre-commit or brew install pre-commit.
For me, I deleted the old virtual environment and re-Creating it and worked:
$ deactivate
$ python3 -m venv env
$ source env/bin/activate
Hope this would solve your problem, thank you!

Upgrading Python 3.7 to 3.9 on macOS Big Sur

I'm trying to upgrade Python 3.7 to 3.9 on macOS Big Sur. I'm also trying to avoid losing packages that were installed on Python 3.7 and reinstalling them again on Python 3.9
I tried using
brew install python3
brew update && brew upgrade python
which yielded
Already up-to-date.
Warning: python3 3.9.1_7 already installed
However when I run python3 --version it yields Python 3.7.0
Is this an issue with the alias? Is there a way to uninstall Python 3.7 and keep Python 3.9?
Running brew link python3 yields
Linking /usr/local/Cellar/python#3.9/3.9.1_7...
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
rm '/usr/local/bin/2to3'
To force the link and overwrite all conflicting files:
brew link --overwrite python#3.9
To list all files that would be deleted:
brew link --overwrite --dry-run python#3.9
I fixed this frustrating error by first removing the Python 3.7 manually, by deleting it from the Applications folder and then uninstalling Python 3.9 using brew uninstall python3
Next, I downloaded and installed the latest Python from here and it worked!
To save all the installed packages by generating a requirements file, Run
python3 -m pip freeze > requirements.txt
and to install them in another environment, Run
python3 -m pip install -r requirements.txt
I suggest use official binaries:
Download version you need from the python.org
Call the .pkg
Invoke Update Shell Profile.command script under /Applications/Python\ 3.XX/
After all reboot your terminal
Check your Python version. The old version and dependencies remain intact.

Build Failure: How to use Pyenv to install Python 3.8.3 on macOS Big Sur version 11.0.1?

I tried using the command pyenv install 3.8.3 to install Python 3.8.3 but got a build failure error pictured below.
BUILD FAILED (OS X 11.0.1 using python-build 20180424)
Does anyone know how to make the build successful on macOS Big Sur version 11.0.1?
3.8.3 is far too old to support macos 11
At the time of writing, the current 3.8.x release 3.8.7 has only partial support for big sur (it will build and run, but it lacks some system library support). Full support is planned in python 3.8.8
In my case, i use path python to install all versions. this command resolve all problems:
pyenv install --patch 3.6.8 <<(curl -sSL
https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
In case you need another version, just change 3.6.8 for your version.
Feels like it's Mac issue. Not sure what was actually happened, but it worked after I uninstall the CLT then reinstall.
Below is the steps I have done:
Uninstall current CLT:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Remember to install "Xcode" from the App Store if not.
Run sudo xcodebuild -license accept then update pyenv in Homebrew should make things work.
If you have brew installed you can use it to install python3.8. Try using:
brew install python#3.8
Also, you can use python3.8 -m virtuanenv to create a virtual environment

Switching Python version installed by Homebrew

I have Python 3.8 and 3.9 installed via Homebrew:
~ brew list | grep python
python#3.8
python#3.9
I want to use Python 3.9 as my default one with python3 command. I tried the following:
~ brew switch python 3.9
Error: python does not have a version "3.9" in the Cellar.
python's installed versions: 3.8.6
I tried to uninstall Python and reinstall it, but it's used by other packages:
~ brew uninstall python
Error: Refusing to uninstall /usr/local/Cellar/python#3.8/3.8.6
because it is required by glib and php, which are currently installed.
You can override this and force removal with:
brew uninstall --ignore-dependencies python
How can I use Python 3.9?
There is an Homebrew known issue related to side by side install of Python 3.8 / 3.9. To workaround, following commands should work for you:
brew unlink python#3.9
brew unlink python#3.8
brew link --force python#3.9
Re-opening your terminal or execute command rehash can be required to take account the change.
Use pyenv. It's a software that lets you switch between any and all Python versions installed on your system. To install pyenv, use the following code in the command-line:
curl https://pyenv.run | bash
exec $SHELL
Then find the name of the python version you want to switch to with this:
pyenv versions
And select it with this:
pyenv global <version-name>
In your case, it's most likely named 3.9.0.
Updated MacOs Monterrey
For who are facing this problem add the pyenv path to your ~/.zshrc shell file.
export PATH="/Users/username/.pyenv/shims:${PATH}
eval "$(pyenv init --path)
Run in the terminal:
source ~/.zshrc
Check it out:
python3 --version
Font from the issue on GitHub.

How-To Update Python 3.x When the New Version Rolled - Out on macOS

I installed Python 3.6.5 on macOS. How can I update Python When the new version rolled out ? Thanks.
You do have the latest version of python3
You can use homebrew to update python
To install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install python (if not installed)
brew install python3
Finally, update the python (this is what you are looking for)
brew upgrade python3
Nice explanation here -
https://apple.stackexchange.com/questions/201612/keeping-python-3-up-to-date-on-a-mac

Categories

Resources