Installing Python 3.6 on MacOS Mojave for QGIS
Asked Answered
I

1

7

I'm trying to install QGIS 3.4.1 on Mac OS Mojave. QGIS install comes as a pkg file, specifically requires python 3.6 (will not work with 3.7), Mac ships with 2.7, and homebrew installs python3 with 3.7.1.

To the Python devs out there - what's the best way of installing Python 3.6 and then QGIS here? Pyenv, venv, pipenv, virtualenv? How would QGIS always find python 3.6 - during install and later when I run it?

What I want to accomplish is run QGIS on python 3.6 and not have python 3.6 change either default Mac 2.7 python, or homebrew python3.

Irresolute answered 18/11, 2018 at 18:50 Comment(2)
What's the problem? Is your question about installing Python (in the title) or QGIS (in the post itself)?Antenna
My question is about installing QGIS, which requires installing Python 3.6 - so specifically, installing Python 3.6 in such a way that it doesn't clobber current python install and also let's me run QGIS.Irresolute
J
10

As stated in QGIS documentation:

The current QGIS package uses the python.org Python 3.6, at least version 3.6.5, the “macosx10.9” build - other distributions are not supported.

So you can install Python 3.6 downloaded from python.org website. Please follow these simple steps:

Prerequisites

Please verify the Xcode developer tools are installed:

xcode-select -p

should return

/Library/Developer/CommandLineTools

if not, please run this command

xcode-select --install

Python installation

Go to https://www.python.org/downloads/mac-osx/ and download the Python 3.6 macOS 64 bit installer (currently 3.6.7). This is a pkg installer you can run like many other software. If you don't want to replace the Python 3.7 you installed from brew, ensure this Python distribution is NOT added to the system $PATH. By default, it will install under /Library/Frameworks/Python.framework/Versions/3.6.

QGIS install

Now you have the correct Python installed, download QGIS package.

Install the pkg in the right order

Run QGIS and open "Preferences". Go to System > Environment. Check "Use custom variables" and click green "plus" sign. Under "Apply", select "Prepend", set PATH as variable and paste

/Library/Frameworks/Python.framework/Versions/3.6/bin:

as Value. This will help QGIS locating the correct python interpreter. Click OK, restart QGIS and you should be done.

Jada answered 23/11, 2018 at 15:28 Comment(6)
I don't want to modify either my python3 or python versions to run an arbitrary python program though - so I specifically want to run Python 3.6 with QGIS and retain python3 as latest Python 3 and python as latest Python 2.7Irresolute
Ok, I misunderstood your question. I edited my answer accordinglyJada
I guess let me clarify it further - I specifically do want Python 3.7 as python3 and Python 2.7 as python. So QGIS needs to run with Python 3.6 thru some kinda virtualenv or other means.Irresolute
Edited the answerJada
Another comment to anyone who'll end up reading this - QGIS ignores python in the system path and looks for python under /Library/Frameworks - and installing Python 3.6 directly or symlinking it there solves that issue.Irresolute
For what its worth, I am using pyenv and had 3.6.7 installed and configured (global) and it wasn't working. I attempted to symlink with no luck. Installing the offical 3.6.7 did the job without breaking anything...yet.Bloodroot

© 2022 - 2024 — McMap. All rights reserved.