31

Kyngchaos installer is not finding python3. I installed python3 using HomeBrew and is not located at /usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/bin/python3.6

How do I tell the QGIS installer to recognize that python3 is installed?

I had previously installed GDAL using HomeBrew, so tried reinstalling (or installing another version wherever it might end up) thinking it might help with the situation, but the QGIS3 installer still can't find python 3.

The installation error is a popup that comes up as soon as the installer is open and says "python3 QGIS requires Python 3.6."

For non Mac users, most seem to rely on Kyngchaos to provide an installer for QGIS and he has just released the installer for v3.

Update: answered my own questions below. Don't use HomeBrew unless you know enough to point the QGIS installer/QGIS to the right version (which I certainly don't), but use the python3 installer version linked to in the ReadMe.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Greg
  • 899
  • 1
  • 7
  • 16
  • Where are the Kyngchaos installers? I can't find them anywhere. – Alex Leith Mar 11 '18 at 22:18
  • Since he hasn't updated the link, I guessed it to be http://www.kyngchaos.com/files/software/qgis/QGIS-3.0.0-1.dmg – Greg Mar 11 '18 at 22:23
  • It's not promoted on his webpage yet is it? – Alex Leith Mar 11 '18 at 22:49
  • 2
    "QGIS 2.18.15-4" is repeated twice at http://www.kyngchaos.com/software/qgis and the first should be "QGIS-3.0.0-1". I think it's a copy and paste error, in other words he copied the old link etc and forgot to update. How would I guess this—not because I've ever done it! – Greg Mar 11 '18 at 22:58
  • @Alex Leith: I wasn't very clear in answering your question: There are two categorieson the page: Current and Long Term Support—the same version is listed in both. But as you say he doesn't specify that it's the new version 3 and his blog only mentions that he's working on it. But it is there and it works although I'm finding some plugins I use are missing or are replaced by something else that I haven't discovered yet. – Greg Mar 11 '18 at 23:02
  • Hi @greg, it looks to me like it's unfinished. I saw his announcement on the homepage of Kyngchaos, and he said it wasn't tested. He's probably working furiously as we speak! – Alex Leith Mar 11 '18 at 23:12
  • 4
    Today (12 Mar 2019), the link at http://www.kyngchaos.com/software/qgis is updated. – Greg Mar 12 '18 at 18:47
  • I wonder if a symlink might solve the problem. The official python binary downloaded and installed per the answer below installs to: /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 – songololo Mar 13 '18 at 10:46
  • Okay I did the exact thing specified in the Read Me and downloaded python 3.7.2 - the most recent version - direct from python.org. No dice. Do I have to install an older version? QGIS just won't recognize it. EDIT: Tried it with Python 3.6 and it worked. Guess they're serious about which version. – Anna Jan 30 '19 at 20:23
  • @Anna I've lost track of this discussion. But I recently started from scratch with a new iMac and my notes say that I just dowloaded QGIS from qgis.org. I don't think I installed Python, just using the version with High Sierra or Mojave. python --version: Python 2.7.10 QGIS3 works. You don't say which macOS you're on, nor which QGIS version. Update: Python is included with the installer at qgis.org. I see when I launch QGIS there is a line "Python version: 3.6.6". – Greg Jan 31 '19 at 01:04
  • You can see python in the app at /Applications/QGIS3.4.3.app/Contents/Resources/python/ – Greg Jan 31 '19 at 01:10
  • The Readme is talking about macOS 10.9. We're up to 10.14! In other words the Readme is a bit out of date. – Greg Jan 31 '19 at 01:21

6 Answers6

37

NEW UPDATE

QGIS3 can now be installed from osgeo's homebrew tap, which saves mucking about with python symlinks... i.e.

brew tap osgeo/osgeo4mac
brew install qgis

Then type qgis in the terminal to launch, then pin the dock menu icon to simplify launching in future.

Note that the installation console logs will also provide an example for how to symlink qgis to your applications directory.

Due to some current issues, it may be necessary to run ulimit -n 1024 from terminal as a workaround for the Too many open files @ rb_sysopen - /usr/local/var/homebrew/locks/xmlto.formula.lock error. You may also need to run brew install qgis more than once for all packages to find each other.

OLD UPDATE

(This method requires updating symlinks when versions change... i.e. not ideal)

For those who use homebrew, it is probably better to just use a symlink, otherwise all kinds of havoc could emerge. e.g. the official python binary will modify your ~./bash_profile so that python3 and pip3 no longer point to brew...

In my case I've now symlinked the homebrew version (along the lines of the discussion in the answer provided by @Evenfire):

sudo ln -s /usr/local/Cellar/python/3.6.5/Frameworks/Python.framework /Library/Frameworks/Python.framework

QGIS3 then complained that certain python packages were missing, which can be installed with pip3, e.g.

pip3 install owslib PyYaml psycopg2 jinja2 pygments plotly

It might also complain about gdal, in my case I simply used brew:

brew install gdal

ORIGINAL

(This method is not recommended for brew users!)

I've also got python3 installed via brew and am running into the same difficulty.

What seems to work is to install the official python binaries which install to /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.

From trial and error, this has to be done before the 1 Install GDAL Complete.pkg package is installed, which otherwise installs against the wrong python and QGIS 3 will complain about missing python packages.

Those with time to experiment could conceivably try symlinks to get around directly using the brew (or other) python3.

songololo
  • 1,694
  • 14
  • 19
  • Thanks! The install of python just before the "1 Install GDAL Complete.pkg" did the trick for me and solved the error "module osgeo not found". – Javier Fajardo Mar 13 '18 at 18:35
  • Do you have GDAL also installed with homebrew? I created the symlink for python but the installer is asking for GDAL2.2 which I have installed with homebrew. – Duccio A May 18 '18 at 10:32
  • In my case I don't have gdal installed with homebrew. My understanding is that QGIS specifically depends on KyngChaos' version (unfortunately!). So it might be necessary to install the gdal provided with QGIS and then it might work. – songololo May 18 '18 at 13:26
  • I made the mistake of installing the GDAL package before python. To get everything to work, I installed Python3.6, then additional pip3 packages as mentioned above, deleted /Library/Frameworks/GDAL.framework directory and installed the GDAL.framework installer + QGIS3 installer again. – spatialthoughts Jul 12 '18 at 12:09
  • 1
    I noticed that installing binaries for the newer python3.7 is not supported by the newest QGIS installer! python3.6.6 is necessary, and it can be downloaded from the link that you provided in this answer. – Javier Fajardo Jul 18 '18 at 15:06
  • 2
    This might be a very stupid question, but once you've installed qgis via homebrew, how do you run it? Figured it out: qgis3 is the command. – Juan Francisco Saldarriaga Aug 20 '18 at 17:13
  • Yes, the first time just type qgis3 in terminal, though you can then right click the icon in the dock > Options > Keep in dock, then just click the icon for subsequent launches! – songololo Aug 20 '18 at 20:49
  • Installation from the tap is not working as of September 2020. May be related to this: https://github.com/OSGeo/homebrew-osgeo4mac/issues/1376 – bwall Sep 21 '20 at 18:57
29

If you have installed Python3 with Homebrew, you can use symlinks to comply with the installer needs (as suggested by @shongololo).

It seems, the installer needs Python3 installed at (thanks @shongololo): /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.

(Install python3 using Homebrew to follow this part)

Find the Cellar directory on your machine. Mine is at: /usr/local/Cellar. Then find this directory: /usr/local/Cellar/python3/3.x.y_z/Frameworks/Python.framework (where 3.x.y_z is the python3 version you want to use, for me it is 3.6.4_2). This is the directory we want the installer to find. We need to link to this directory from the directory the installer is looking at by making a Symbolic Link.

Using the ln command (ln -s TARGET_FILE_TO_LINK_TO LINK_NAME): ln -s /usr/local/Cellar/python3/3.x.y_z/Frameworks/Python.framework /Library/Frameworks/Python.framework will do the trick. You certainly need to sudo.

This has worked for me.

(The "Cellar" is a place that all your "kegs" go. Homebrew installs packages to their own directory (in the Cellar) and then symlinks their files into /usr/local/. [from Ryan Kulla's blog])

Evenfire
  • 391
  • 2
  • 6
  • Thanks for this info. I fixed already with "default" installer. Since I don't need Python for anything else that will work for me. I in general prefer to use Homebrew for consistency. And Apple has v2 installed by default.

    Was are the tradeoffs between using the two installers (Homebrew and one from the python site)? I guess that Homebrew will keep python updated more easily. And you can uninstall easily. I have no idea how to do that with the other install method. Got me thinking to go back to the Homebrew version since I know how to manage it.

    – Greg Mar 13 '18 at 19:59
  • @greg homebrew is easier to much easier to manage, e.g. uninstalls. It also keeps your various package interdependencies interlinked quite nicely. – songololo Mar 14 '18 at 09:34
  • 1
    @evenfire thanks for the nice explanation. brew info python is a handy way to quickly find paths to existing brewed python installs – songololo Mar 14 '18 at 09:36
  • @Greg I'm by no means a 'pro' of Homebrew. I use to easily install/uninstall packages and their dependancies. I discovered it when i grew tired of not knowing what each installer was doing and moving its files. – Evenfire Mar 14 '18 at 10:11
  • 4
    A heads-up that brew recently changed their default python to v3, so for those that have recently updated / upgraded their homebrew, the above paths would contain python and not python3 – songololo Mar 14 '18 at 10:13
  • @shongololo that's... good to know! – Evenfire Mar 14 '18 at 10:15
  • @Evenfire and shongololo I apparently wasn't clear. I use Homebrew regularly. But since your explanation of how to use the Homebrew version wasn't yet posted it was easier for me to go with with the other version. The one thing I wondered about with using the Homebrew version was what happens if python3 is updated? If I understand the alias is hard wired for a particular version. – Greg Mar 14 '18 at 19:10
  • @Greg Exactly, with this method, you would have to replace the symlink if you want to use an other version of python. – Evenfire Mar 14 '18 at 21:13
  • 4
    How could I connect the framework file with anaconda python? (I cannot find python.framework in anaconda dirs) – natsuapo Mar 15 '18 at 14:16
  • the symlink option is sloppy, but it has worked for me on QGIS3 by linking to the homebrew python.framework. However, I've found that this completely breaks qgis-2, causing a traceback ending in ImportError: cannot import name _remove_dead_weakref If anyone has a workaround for this, please share. – grad student May 21 '18 at 15:39
  • In my case, the cellar pointed to /usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework and not /usr/local/Cellar/python3/3.6.5_1/Frameworks/Python.framework – Hamady C. Jan 30 '19 at 12:53
5

I followed the link that came with the QGIS installer to https://www.python.org/downloads/ and installed python3 that way. The QGIS installer was then happy.

This seems to be contradicted by comments here:

"Because QGIS links the python library, you must install the python.org Python 3.6. You can't substitute another python 3 installation. Sorry, that's the way it is."

Posted at http://www.kyngchaos.com/blog/2018/20180315_qgis_3_must_use_python.org_python_3. If I knew how to contact William Kyngesbury, I would. He is performing a great service though.

Greg
  • 899
  • 1
  • 7
  • 16
4

Another version of pyenv and symlinking, using brew just for dependencies.

Recommended location to install pyenv is ~/.pyenv ($HOME/.pyenv), but could be any location.

  1. clone pyenv repository (maybe adapt ~/.pyenv to /path/to/pyenv)

    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    
  2. setup pyenv in ~/.bash_profile (maybe adapt $HOME/.pyenv to /path/to/pyenv, be aware, that the third line must stay the final one of .bash_profile, even after future updates)

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
    
  3. restart shell

    exec "$SHELL"
    
  4. install dependencies readline and xz the easy way with brew

    brew install readline xz
    
  5. install Python 3.6.x containing Python.framework (maybe adapt version number)

    env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.8
    
  6. always rehash after adding a new Python version to pyenv

    pyenv rehash
    
  7. symlink Python.framework

    sudo ln -s $(pyenv root)/versions/3.6.8/Python.framework /Library/Frameworks/Python.framework
    

Now the QGIS 3.6.0 installer from qgis.org should run fine plus macOS is well prepared for multiple Python versions, playing nice with system's Python.

stackless
  • 61
  • 2
  • This worked better for me than the homebrew install, which was really unhappy with existing dependencies I had installed. – MattyB Jul 16 '19 at 03:35
3

A version using pyenv and brew:

brew install pyenv
env PYTHON_CONFIGURE_OPTS="--enable-framework CC=clang" pyenv install 3.6.5
sudo ln -s /Users/$USER/.pyenv/versions/3.6.5/Python.framework/Versions/3.6 /Library/Frameworks/Python.framework/Versions/3.6
sudo cp -R /Users/$USER/.pyenv/versions/3.6.5/Python.framework/Versions/3.6 /Library/Frameworks/Python.framework/Versions/3.6
sudo cp -r /Users/$USER/.pyenv/versions/3.6.5/lib/python3.6/lib-dynload/ /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
sudo cp /Users/$USER/.pyenv/versions/3.6.5/lib/python3.6/lib-dynload/_struct.cpython-36m-darwin.so /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload/_struct.cpython-36m-darwin.so
# 
jmunsch
  • 131
  • 4
  • 2
    it should be enough just to run first 2 lines and then ln -s ~/.pyenv/versions/3.6.5/Python.framework /Library/Frameworks/Python.framework – Alex Markov Jul 04 '18 at 08:53
0

I faced the same issue when installing QGIS on mac.
It was failed, although I tried to softlink it with other python installed by anaconda, etc.
The way I solved the issue: download related python version in python.org and install.

Chokurei
  • 1
  • 1