Install python#2 on Mac with M1 chip - python

Long story short, I want to install Apache Cassandra on a MacBook Pro with M1 chipset.
In order to install it, one must install other softwares before, one of them being python which must be updated to the latest version. I have followed this tutorial.
This is what terminal shows up when asking about python existing version:
> python --version
Python 2.7.16
In tutorial they are updating it to 2.7.17, so I try to do the same:
> brew install python#2
and this is the output:
Warning: No available formula or cask with the name "python#2". Did you mean bpython, ipython, jython or cython?
==> Searching for similarly named formulae...
These similarly named formulae were found:
bpython ipython jython cython
To install one of them, run (for example):
brew install bpython
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.
Any ideas how to overcome this issue?

I could install 2.7.18 on M1.
brew install pyenv
pyenv install 2.7.18
Set the python version.
pyenv global 2.7.18
Export PATH if necessary.
export PATH="$(pyenv root)/shims:${PATH}"
Add if necessary.:
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc

Sometimes you will get some errors like missing something
if you are using rosetta then run
arch -arm64 pyenv install 2.7.18

Related

Error: No similarly named formulae found. Error: No available formula or cask with the name "python"

So, I'm using macOS Big Sur. So I typed:
python --version
Python 2.7.16
brew install python
I got this error message when I want to update my python via my terminal.
Error: No similarly named formulae found.
Error: No available formula or cask with the name "python".
It was migrated from homebrew/cask to homebrew/core.
I would like to update it to Python 3, so when I run my commands on VSC. I can just type python instead of python3. What does this error message mean?
Run this command in terminal:
rm -fr $(brew --repo homebrew/core)
Then try:
brew install python3
it will install python 3.9.
this has worked for me. use the exact version as such python#3.9
First search available packages using
brew search python
Then install the version you want ex:
brew install python#3.9

Have python 3 and pip 3 installed but pip -V shows 19.2.3

I have followed the instructions at https://opensource.com/article/19/5/python-3-default-mac:
Now, python -V shows 3.8.1, but pip -V still shows 19.2.3.
I checked with which pip3, which shows
/Library/Frameworks/Python.framework/Versions/3.8/bin/pip3, but using
echo "alias pip=/Library/Frameworks/Python.framework/Versions/3.8/bin/pip3>> ~/.zshrc does not seem to work.
pip -V gives: pip 19.2.3 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8).
I have MacOS Cataline 10.15.3. Can someone help please?
There seems nothing wrong with your setup. pip has a version number that is independent of that of python. Your python version is 3.8 and the corresponding pip (which resides in python3.8/site-packages/pip) has version 19.2.3. You have set up everything just fine
In fact I was trying to install python in pyenv and get my IDLE to work. The following worked for me (mostly from https://github.com/pyenv/pyenv/issues/1375; Installed Python 3 on Mac OS X but its still Python 2.7; https://opensource.com/article/19/5/python-3-default-mac, with a few additional steps). Thanks for your help. I posted my solution at https://github.com/pyenv/pyenv/issues/1375, too, for reference)
ran $brew install pyenv
ran $brew install tcl-tk
Output after "brew reinstall tcl-tk':
tcl-tk is keg-only, which means it was not symlinked into /usr/local,
because tk installs some X11 headers and macOS provides an (older) Tcl/Tk.
If you need to have tcl-tk first in your PATH run:
echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc
(I added it to ~/.zshrc as the first line)
For compilers to find tcl-tk you may need to set:
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
(I added these two to ~/.zshrc, too, after adding the above)
For pkg-config to find tcl-tk you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
(I added this two to ~/.zshrc, too, after adding the above)
To get tcl-tk 8.6 to work with the pyenv install of python, I found:
/usr/local/Cellar/pyenv/1.2.13/plugins/python-build/bin/python-build
and replaced the following:
$CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
with:
$CONFIGURE_OPTS --with-tcltk-includes='-I/usr/local/opt/tcl-tk/include' --with-tcltk-libs='-L/usr/local/opt/tcl-tk/lib -ltcl8.6 -ltk8.6' ${!PACKAGE_CONFIGURE_OPTS} "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" || return 1
ran $pyenv install 3.8.1
Installed Python-3.8.1 to /Users/ryan/.pyenv/versions/3.8.1
ran $pyenv global 3.8.1
Refreshed the current terminal and checked
$pyenv version
output: 3.8.1 (set by /Users/ryan/.pyenv/version)
Ran $python -V
output: Python 3.8.1
ran $pip install --upgrade pip (since I had previously already installed pip using $pip install)
output: Successfully installed pip-20.0.2
Tested my tcl-tk installation with $python -m tkinter -c 'tkinter._test()'
Output: Tk window popped up. Hit ‘Quit’ to back to Terminal.
Ran $ idle
Output: Python 3.8.1 Shell window popped up.
The installation was done on a MacBook Pro with macOS Catalina 10.15.3.

Python2 version set to Python3 in version check

So I was trying to install OpenCV in on the MacOS following this tutorial: https://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/
In step 3 the versions of python should be python 2.x checked with python --version and python 3.y checked with python3 --version. However on both commands I am getting Python 3.6.4. How can I fix this? I have tried to install python 2 again with brew install python#2 and the output is python#2 2.7.14_1 is already installed. which python shows /usr/local/bin/python whereas which python3 shows /usr/local/bin/python3.
If you installed Python 2 and Python 3 with Homebrew, then the Python 2 binary is named python2, but will not be linked into /usr/local unless you use brew link with the --force flag.
See brew info python#2:
$ brew info python#2 | grep Caveats -A 4
==> Caveats
This formula installs a python2 executable to /usr/local/opt/python#2/bin
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="/usr/local/opt/python#2/libexec/bin:$PATH"
$ brew info python#2 | grep 'not symlinked' -A 2
This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
You can run
/usr/local/opt/python\#2/bin/python2
if you need to run it directly, or you can force homebrew to link it in anyway with:
brew link --force python#2
at which point /usr/local/bin/python2 will be added.
The tutorial is rather outdated; how homebrew handles Python has changed. Just use python2 wherever it uses python.
To further address the tutorial:
brew linkapps is deprecated
the homebrew/science tap is deprecated, the formulas in that tap have been migrated, opencv3 can be installed without additional taps.
the current version of the opencv3 natively supports both Python 2 and 3, no configuration switches required
the formula directly depends on the Python 2 and 3 formulae, installing opencv3 will automatically install Python.
So just run brew install opencv3, follow any additional instructions that command prints (could be none).
Do make sure you update Homebrew as there were some dependencies missing (see my bug report with Homebrew). If you don't, you'll have to run brew install hdf5 tesseract to install dependencies that should have been optional.
The tutorial is almost entirely obsolete now.

Attempted install of Python 3 via homebrew fails on Mac OS X Sierra

I'm trying to install Python 3 alongside 2.7 with Homebrew but am receiving an error message I can't find a resolution to.
When attempting brew update && brew install python3 I get the following error:
Error: python 2.7.12_2 is already installed
To upgrade to 3.6.4_3, run `brew upgrade python`
I want to leave the python 2.7 installation alone so I can have both Python 2 & 3 accessible on my machine so I'm nervous that upgrading will overwrite the current 2.7 installation.
I figure I can still perform a clean side-by-side install with the package from python.org, but I want to know why I'm getting this homebrew error
brew doctor shows the following Warnings containing python
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
brew install python#2
To be honest, and what I also have on my own system, is Python 3 as the default and Python 2 available if I need it. With homebrew, you can just update your default as it wants you to do with the upgrade. That means when you run python, Python 3 will run as the default.
For Python 2, install brew install python#2. When you want to run Python 2, just run python2 in the terminal and you'll have it.
Python install will run once you fix the broken links by running brew link, and the missing link component.
These usually don't need SUDO, they will link then and run brew doctor once they have all been linked.

How to make Mac OS use the python installed by Homebrew

I have searched online for a while for this question, and what I have done so far is
installed python32 in homebrew
changed my .bash_profile and added the following line to it:
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
but when I close the terminal and start again, I type 'which python', it still prints:
/usr/bin/python
and type 'python --version' still got:
Python 2.7.2
I also tried the following instruction:
brew link --overwrite python
or try to remove python installed by homebrew by running this instruction:
brew remove python
but both of the above two instructions lead to this error:
Error: No such keg: /usr/local/Cellar/python
can anybody help, thanks
brew install python or brew info python output mentions:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been installed into
/opt/homebrew/opt/python#3.9/libexec/bin
So running
% echo 'export PATH=/opt/homebrew/opt/python#3.9/libexec/bin:$PATH' >> ~/.zprofile
% source ~/.zprofile
# For bash use ~/.bash_profile.
gets you those symlinks created by Homebrew - python=python3, pip=pip3 etc
% python --version
Python 3.9.10
% pip --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
If you want to install Python 3 using Homebrew:
$ brew install python3
==> Downloading http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python3-3.3.0.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.3.0 --enable-ipv6 --datarootdir=/usr/local/Cell
==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0
==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python3/3.3.0/share/python3
==> Downloading https://pypi.python.org/packages/source/d/distribute/distribute-0.6.35.tar.gz
Already downloaded: /Library/Caches/Homebrew/distribute-0.6.35.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/pip-1.3.1.tar.gz
==> /usr/local/Cellar/python3/3.3.0/bin/python3.3 -s setup.py install --force --verbose --install-li
==> Caveats
Homebrew's Python3 framework
/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework
Distribute and Pip have been installed. To update them
pip3 install --upgrade distribute
pip3 install --upgrade pip
To symlink "Idle 3" and the "Python Launcher 3" to ~/Applications
`brew linkapps`
You can install Python packages with
`pip3 install <your_favorite_package>`
They will install into the site-package directory
/usr/local/lib/python3.3/site-packages
Executable python scripts will be put in:
/usr/local/share/python3
so you may want to put "/usr/local/share/python3" in your PATH, too.
See: https://github.com/mxcl/homebrew/wiki/Homebrew-and-Python
Once installed update your system PATH variable, add the next line to ~/.bash_profile
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
And then:
$ source ~/.bash_profile
Now launch Python:
$ python3
Python 3.3.0 (default, Mar 26 2013, 10:01:40)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
You can check python3 path:
$ which python3
/usr/local/bin/python3
You may try adding this line to your .bash_profile
alias python='python3'
I came through the same issue and did some research. I found that someone has created a bug for the same issue under the azure/cli repository. You can find that issue here. I am providing the same solution here which was very easy and fixed my issue:
Most probably the Brew is broken and needs some patching or fixing. So run brew doctor command which will give you a summary about what is happening.
Below is what I got:
mymac:bin sidmishra$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: The following directories do not exist:
/usr/local/sbin
You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/sbin
sudo chown -R $(whoami) /usr/local/sbin
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/LibSideSyncOSX9.dylib
/usr/local/lib/ss_conn_lib.dylib
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python
The awesome stuff about the command brew doctor is that it not only tells you issues but also suggests you the solution steps in most of the cases.
So, I ran all the commands suggested by the brew and to link I ran the following command:
brew link python
Above command threw me an error:
mymac$ brew link python
Linking /usr/local/Cellar/python/3.7.1... Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks/Python.framework
It seems that /urs/local/Frameworks doesn't have enough rights for my current user. So, I ran the following command and gave enough rights to my current user:
sudo chown -R $(whoami) /usr/local/Frameworks/
After running above command I ran linking command again, and it worked!!!
mymac$ brew link python
Linking /usr/local/Cellar/python/3.7.1... 1 symlinks created
Now run following command to get the current selected python version:
python --version
Above command should give you 3.7.1 (as of 21st Dec 2018) or new version for the python. There might be a chance that your Mac would have python2 set by default. If the version is not python3 then you have to a couple of steps to use the latest python3 over python2 version. Here are the steps:
Using Shell:
Open ~/.bash_loginor ~/.bash_profileor ~/.cshrcor ~/.profileor ~/.tcshrcor ~/.zprofile, whatever shell you are using for commands, in edit mode. You may have to use sudo to edit them.
Add following steps to it:
PATH="/Library/Frameworks/Python.framework/Versions/3.2/bin:${PATH}"
export PATH
Also, add following for backup:
alias python=python3
OR
Using homebrew:
Run following commands to unlink python2 and link python3:
mymac$ brew unlink python#2
mymac$ brew link python#3
Above will unlink python2 and link python3.
Hope some of you will get helped from this answer.
Good Day!!!
From $ brew info python:
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Then confirm your python executable corresponds to the correct installation:
$ which python or
$ python --version
Installing with Homebrew is recommended on macOS. That being said, Python 2.7 comes with Mac OS; however, it is deprecated and will be removed soon. As such, you should be using Python3 and newer.
Install Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Run brew install python
Once Python is installed, Homebrew will say that the installation is complete, but that you already have Python 2.7 installed. This is nice, but we want to set it to actually see python3 as an option
Use brew link
Confirm by running which python3, the path should be /usr/local/bin/python3

Categories