OSGeo4W shell with python3
There's no need to edit batch files (and break python 2.7 in the process) or set environment variables manually.
Just run py3_env
which sets the shell up for Python 3 automatically, then run python3
.
From a OSGeo4W shell with just python 2 & 3 installed:
C:\> o-help
-={ OSGeo4W Shell Commands }=-
dllupdate pip3 sqlite3
easy_install3 python textreplace
nircmd python3 vcredist_2015_x64
nircmdc pythonw xxmklink
osgeo4w-setup pythonw3
make-bat-for-py py3_env <<<=== This is the command you want
o-help setup-test
o4w_env setup
C:\>python3
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000013e8 (most recent call first):
^C
C:\>py3_env
C:\>python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
There is a not well documented command build into OSGeo4W Shell which sets the shell up to python3 as Luke mentions
py3_env
Basically it sets your PYTHONHOME and the correct PATH. Then you can call Python3 with python3
.
C:\>py3_env
C:\>SET PYTHONPATH=
C:\>SET PYTHONHOME=C:\OSGEO4~1\apps\Python36
C:\>PATH C:\OSGEO4~1\apps\Python36;C:\OSGEO4~1\apps\Python36\Scripts;C:\OSGEO4~1\apps\Python27\Scripts;C:\OSGEO4~1\bin;C:\Windows\system32;C:\Windows;C:\Windows\WBem
C:\>python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Update with auslander's comment:
To use Python3 with the OSGeo4W shell that comes with QGIS 2 you have to change the file {path you installed qgis}\etc\ini\python-core.bat
:
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python36
PATH %OSGEO4W_ROOT%\apps\Python36\Scripts;%PATH%
If you want to make the change permanent you can modify the batch file OSGeo4W.bat located in your QGIS (or OSGEO) directory and just add:
call "py3_env"
below the line calling
call "%~dp0\bin\o4w_env.bat"