This might be just a syntax error in Windows Powershell, but I'm not able to run a python script with a specific python version (I have two installations).
I have a batch file in which the following command works:
"C:\Program Files\QGIS 2.18\bin\python.exe" myscript.py
But if I open a PowerShell in the folder containing the python script, I get an error:
At line:1 char:45
+ ... C:\Program Files\QGIS 2.18\bin\python.exe" myscript.py
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token 'myscript.py' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
I tried also without double-quotes, with single-quotes, and by specifying the path also to the python script:
"C:\Program Files\QGIS 2.18\bin\python.exe" C:\mydata\myscript.py
With quotes on both parts:
"C:\Program Files\QGIS 2.18\bin\python.exe" "C:\mydata\myscript.py"
But with a similar error.
What is the correct way to write this command?
bin\python.exewhen you runpython.exe myscript.pyis becausemyscript.pydoesn't exist inbin/of QGIS. Instead go tomydata/directory and then runC:\Program Files\QGIS 2.18\bin\python.exe myscript.pywhich will use thepython.exepath provided and then runmyscript.pypresent in themydatadirectory.C:\mydatawhich is where I launch the PowerShell. It is because that didn't work that I included the path to the.pyfile in the first place.pythonon your path, what do you get when you runwhere pythonon yourcmd?cmd, that returns the paths for both of my installs:C:\ProgramData\Anaconda3\python.exeC:\Program Files\QGIS 2.18\bin\python.exe"C:\Program Files\QGIS 2.18\bin\python.exe" myscript.pyfromcmdinstead ofps?