I just switched from MacPorts to HomeBrew. After installing all the required XCode versions and other software I tried installing python using homebrew: I think it successfully installed, but when I do which python it still shows me 2.7.3 which I think is the version shipped with Mountain Lion.
which python
/usr/local/bin/python
python --version
Python 2.7.3
so I tried to install again
brew install python --framework --universal
Warning: python-2.7.5 already installed, it's just not linked
But it says python 2.7.5 already install and not linked, I tried to do brew link python
That led me to following message so, I have no idea what I should be doing:
Linking /usr/local/Cellar/python/2.7.5... Warning: Could not link python. Unlinking...
Error: Could not symlink file: /usr/local/Cellar/python/2.7.5/bin/smtpd2.py
Target /usr/local/bin/smtpd2.py already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
brew link --overwrite formula_name
To list all files that would be deleted:
brew link --overwrite --dry-run formula_name
After installing python3 with brew install python3
I was getting the error:
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied # dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks
After typing brew link python3 the error was:
Linking /usr/local/Cellar/python/3.6.4_3... Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks
To solve the problem:
sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/*
brew link python3
After this, I could open python3 by typing python3 👍
(From https://github.com/Homebrew/homebrew-core/issues/20985)
In the Terminal, type:
brew link python
If you used
brew install python
before 'unlink'
you got
brew info python
/usr/local/Cellar/python/2.7.11
python -V
Python 2.7.10
so do
brew unlink python && brew link python
and open a new terminal shell
python -V
Python 2.7.11
For those looking for a version re-link using brew, I've found this command useful:
brew unlink python#3.9 && brew link python#3.10
It is possible that some errors appear, like:
Error: Could not symlink bin/pip3
Target /usr/local/bin/pip3
already exists. You may want to remove it:
rm '/usr/local/bin/pip3'
To force the link and overwrite all conflicting files:
brew link --overwrite python#3.10
To list all files that would be deleted:
brew link --overwrite --dry-run python#3.10
So following brew advice and running:
rm '/usr/local/bin/pip3'
brew link --overwrite python#3.10
Just worked for me. To check if symlinks are ok, run: ls -l /usr/local/bin/python*, you should see something like:
/usr/local/bin/python3 -> ../Cellar/python#3.10/3.10.2/bin/python3
/usr/local/bin/python3-config -> ../Cellar/python#3.10/3.10.2/bin/python3-config
/usr/local/bin/python3.10 -> ../Cellar/python#3.10/3.10.2/bin/python3.10
/usr/local/bin/python3.10-config -> ../Cellar/python#3.10/3.10.2/bin/python3.10-config
I think you have to be precise with which version you want to link with the command brew link python like:
brew link python 3
It will give you an error like that:
Linking /usr/local/Cellar/python3/3.5.2...
Error: Could not symlink bin/2to3-3.5
Target /usr/local/bin/2to3-3.5
already exists.
You may want to remove it:
rm '/usr/local/bin/2to3-3.5'
To force the link and overwrite all conflicting files:
brew link --overwrite python3
To list all files that would be deleted:
brew link --overwrite --dry-run python3
but you have to copy/paste the command to force the link which is:
brew link --overwrite python3
I think that you must have the version (the newer) installed.
On OS X High Sierra, I had to do this:
sudo install -d -o $(whoami) -g admin /usr/local/Frameworks
brew uninstall --ignore-dependencies python
brew install python
python --version # should work, returns 2.7, which is a Python thing (it's weird, but ok)
credit to https://gist.github.com/irazasyed/7732946#gistcomment-2235469
I think it's better than recursively chowning the /usr/local dir, but that may solve other problems ;)
You can follow these steps.
$ python3 --version
$ brew unlink python#2
$ brew link python3
$ python3 --version
This answer is for upgrading Python 2.7.10 to Python 2.7.11 on Mac OS X El Capitan . On Terminal type:
brew unlink python
After that type on Terminal
brew install python
brew switch to python3 by default, so if you want to still set python2 as default bin python, running:
brew unlink python && brew link python2 --force
I wouldn't recommend playing around with the symlinks, it's not just to where python points, its the entire env around it as well that maybe mixing version
I would do this:
$ brew install pyenv
$ pyenv install 3.7.3
$ pyenv global 3.7.3
The problem with me is that I have so many different versions of python, so it opens up a different python3.7 even after I did brew link. I did the following additional steps to make it default after linking
First, open up the document setting up the path of python
nano ~/.bash_profile
Then something like this shows up:
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
The thing here is that my Python for brew framework is not in the Library Folder!! So I changed the framework for python 3.7, which looks like follows in my system
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/usr/local/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
Change and save the file. Restart the computer, and typing in python3.7, I get the python I installed for brew.
Not sure if my case is applicable to everyone, but worth a try. Not sure if the framework path is the same for everyone, please made sure before trying out.
I use these commands to solve it.
mkdir /usr/local/lib
mkdir /usr/local/lib/pkgconfig
brew link python
Related
When I build/run/archive my app in Xcode (on MacOS 12.3) I encounter this error:
env: python: No such file or directory
Command Ld failed with a nonzero exit code
I think I might have changed something with regard to my python environment while working on a school project or messed something up there. However, I can not figure out what is wrong.
I tried reinstalling Xcode and python (using brew and pyenv). I also relinked python using brew. But I still encounter the same error.
Which python gives the following results:
which python3
-> /usr/local/bin/python3
And in my ~/.zshrc I have the following line:
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
Any help would be appreciated! If I missed or forgot anything please let me know, I'm quite new to this.
Homebrew only installs the binary python3, just to be safe. Xcode is complaining about a lack of the binary python (note the lack of a 3!).
You have a couple of options:
When installing python3, Homebrew also creates a libexec folder with unversioned symlinks, such as python (what you're missing). Note the Caveats printed when installing it:
$ brew info python
python#3.9: stable 3.9.10 (bottled)
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
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
See: https://docs.brew.sh/Homebrew-and-Python
You could add this directory to your $PATH, such that python and pip become available; something like the following might suffice:
echo 'export PATH="'"$(brew --prefix)"'/opt/python#3.9/libexec/bin:$PATH"' \
>>~/.bash_profile
... although that will need to be modified according to your precise version of Python3, your shell of choice, etc.
Alternatively and more simply, although a little more jankily, you could simply manually create the appropriate symlinks:
ln -s "$(brew --prefix)/bin/python"{3,}
I had posted the same question on nativescript official github and the solution that worked for me was in the answer by the user shilik
Monterey 12.3 removes python 2. All you need to do is to reinstall
python2 back to system from this link
https://www.python.org/downloads/release/python-2718/
install python3
run 'ln -s /usr/bin/python3 /usr/local/bin/python',Create a link to Python
Add -f to be effective.
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
For me the problem was with missing python
env: python: No such file or directory
BUT in the end missing was python version 2.x after updating to macOS Monterey 12.5 (21G72).
Problem was resolved by installing python from:
https://www.python.org/downloads/release/python-2718/
What I've also tried but you probably don't have to do:
sudo brew install python
sudo brew upgrade
sudo ln -s -f /usr/local/bin/python3 /usr/local/bin/python
sudo ln -s $(which python3) /usr/local/bin/python
sudo ln -s $(which python3) /Applications/Xcode.app/Contents/Developer/usr/bin/python
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/python
This took me days of head scratching, and none of the solutions I found on the internet worked.
Eventually what DID work for me was this:
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/python
I used the find command to find all instances of python in the file hierarchy:
find / -name python*
and I saw that there was a symbolic link labelled python3 in /Applications/Xcode.app/Contents/Developer/usr/bin/ that was linked to a python instance deep within the bowels of Xcode.
However there was no symbolic link labelled python which seems to be what Xcode is looking for.
So I created a symbolic link linking python to python3 and that did the trick.
For what it's worth, I installed python via pyenv which I installed through homebrew on a 2020 Mac mini M1.
In my case, created symbolic link for dev_appserver.py like below.
ln -s /opt/local/bin/python2.7 /usr/local/bin/python
ln -s /opt/local/bin/python2.7 /usr/local/bin/python2
Command location and version should be adapted to your environment.
I was able to solve this issue with the above-mentioned answers.
In my case, while I was trying npm install in my node project and was facing this issue.
Note: % brew install python is a prerequisite for all the below steps! Test if python is correctly installed by brew python info
First thing which comes to mind is if python is correctly installed and the path is set correctly.
python --version was giving zsh - python not found error while python3 --version was a success.
Next steps were to set the correct path. I did the below steps and it worked:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
ln -s -f "$(brew --prefix)/bin/python"{3,}
ln -s -f "$(which python3)"{3,}
What I was missing was to run brew install python, and it worked like a charm!
I'm unable to import numpy in Python 2.7 in the shell. I installed Python with brew install, then numpy with sudo pip install. I tried without sudo but I get a permission denied error. Anyway, I get this:
ImportError: dlopen(/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
In /usr/local/bin/ I have the following:
pip
pip2
pip2.7
pip3
pip3.4
And:
python
python-config
python2
python2-config
python2.7
python2.7-config
python3
python3-config
python3.4
python3.4-config
python3.4m
python3.4m-config
pythonw
pythonw2
pythonw2.7
The output of which python is /usr/local/bin/python
As for workaround, try downgrading your Python to 2.7.9 like:
brew switch python 2.7.9
by overriding the existing one, as it seems there is some particular problem with 2.7.10. Then re-link it again (if required).
Also make sure your PYTHONPATH is correct (you don't override it anywhere in your startup files).
That output is normal. Have you tried running brew install openssl followed by brew link --force openssl and then brew install python. The following thread helps describe the issue https://github.com/Homebrew/homebrew/issues/40516
I recently tried to upgrade my Python version via brew and now I am stuck with OSX's system Python because Brew does not seem to be creating a link to it's Python binary.
brew link python outputs (yes I've tried relinking):
Warning: Already linked: /usr/local/Cellar/python/2.7.5
To relink: brew unlink python && brew link python
brew --prefix outputs:
/usr/local
And yet ls /usr/local/python outputs:
ls: /usr/local/python: No such file or directory
Am I misunderstanding how brew is supposed to be working? Shouldn't it be putting a link to a python binary in my /usr/local/bin directory?
In a new shell:
brew install python outputs:
Warning: python-2.7.5 already installed
brew link python outputs:
Warning: Already linked: /usr/local/Cellar/python/2.7.5
To relink: brew unlink python && brew link python
echo $PATH outputs:
/Users/captbaritone/.rvm/gems/ruby-2.0.0-p0/bin:/Users/captbaritone/.rvm/gems/ruby-2.0.0-p0#global/bin:/Users/captbaritone/.rvm/rubies/ruby-2.0.0-p0/bin:/Users/captbaritone/.rvm/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin:/usr/local/MacGPG2/bin:/usr/texbin:/opt/local/bin
And yet which python still outputs:
/usr/local/bin/python
And python --version still outputs:
Python 2.7.1
Here is a lead:
ls -l /usr/local/bin/python outputs:
ls: /usr/local/bin/python: No such file or directory
Any ideas of what I might be doing wrong, or what else I could try?
You didn't link python properly. If you type brew install python on your terminal, it may output as Warning: python-2.7.5 already installed, it's just not linked.
If then, you need to link your python install by typing brew link python. If you face any conflict because of some earlier site-packages, just type as brew link --overwrite python.
Now it should work fine.
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