Discussion:
[Qgis-user] How to get Spyder IDE working with QGIS
John Walker
2018-10-03 00:51:28 UTC
Permalink
Hi, would anyone know how to configure Spyder to work with the QGIS
library? I am finding the python editor in QGIS difficult to work with
because it has no debugger and I cannot run highlighted code. I have tried
a few things:

1. created a new conda environment and installed QGIS via conda using: conda
install -c conda-forge qgis. However I get errors when trying to import
qgis.core

2. installed Spyder within OSGeo4W QGIS python instance i.e.

py3-env
python -m pip install spyder

But this gives errors in the IPython console i.e.

SyntaxError: invalid syntaxFile
"C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
file=sys.stderr)

Thanks for any help.
Luca Manganelli
2018-10-04 08:22:23 UTC
Permalink
Post by John Walker
Hi, would anyone know how to configure Spyder to work with the QGIS
library? I am finding the python editor in QGIS difficult to work with
because it has no debugger and I cannot run highlighted code. I have tried
1. created a new conda environment and installed QGIS via conda using: conda
install -c conda-forge qgis. However I get errors when trying to import
qgis.core
2. installed Spyder within OSGeo4W QGIS python instance i.e.
py3-env
python -m pip install spyder
But this gives errors in the IPython console i.e.
SyntaxError: invalid syntaxFile "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
file=sys.stderr)
Thanks for any help.
You could try the bat in this repository:

https://github.com/frankbroniewski/visual-studio-code-qgis

simply change in the last line of the bat from "code.exe" (this is the
Visual Studio Code IDE) with the exe of your IDE.
Nicolas Cadieux
2018-10-04 12:50:44 UTC
Permalink
Hi John,

If you figure this one out, can you poste the solution? I would like to do the same thing.

Thanks
Nicolas
1. created a new conda environment and installed QGIS via conda using: conda install -c conda-forge qgis. However I get errors when trying to import qgis.core
2. installed Spyder within OSGeo4W QGIS python instance i.e.
py3-env
python -m pip install spyder
But this gives errors in the IPython console i.e.
SyntaxError: invalid syntax
File "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
file=sys.stderr)
Thanks for any help.
_______________________________________________
Qgis-user mailing list
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
John Walker
2018-10-18 05:43:45 UTC
Permalink
Thanks Luca,

That script is actually similar to the script contained
in C:\OSGeo4W64\bin\python-qgis.bat which I have been testing. When I open
a OSGeo4W Shell and execute that script and type 'import qgis.core' into
the python console, it has no issues. When I exit the python console
(pressing ctrl-z) and start spyder3 (which I pip installed previously) it
have no issues with 'import qgis', but it complains when I 'import
qgis.core', giving me the error:

ImportError: DLL load failed: The specified procedure could not be found.

I read on
https://nathanw.net/2014/05/10/setting-up-pycharm-for-pyqgis-and-qt/ that
when you want to get PyCharm working with qgis, you need to change the
python interpreter in PyCharm. So I changed the python interpreter in
spyder to C:\OSGeo4W64\bin\python3.exe, and restarted the kernel. I now get
the following error in spyder's python console:

An error ocurred while starting the kernel
File "C:\OSGeo4W64\apps\Python36\lib\site.py", line 177
file=sys.stderr)

If however I execute PyCharm after running the
C:\OSGeo4W64\bin\python-qgis.bat script, and setting the PyCharm python
interpreter to C:\OSGeo4W64\bin\python3.exe, it works flawlessly. I guess
at this stage I will use PyCharm and abandon my efforts with getting things
working in Spyder, which will be a pain for me as I really love spyder.
Thanks again for your help.

Cheers.
Post by Nicolas Cadieux
Hi John,
If you figure this one out, can you poste the solution? I would like to do the same thing.
Thanks
Nicolas
Hi, would anyone know how to configure Spyder to work with the QGIS
library? I am finding the python editor in QGIS difficult to work with
because it has no debugger and I cannot run highlighted code. I have tried
1. created a new conda environment and installed QGIS via conda using: conda
install -c conda-forge qgis. However I get errors when trying to import
qgis.core
2. installed Spyder within OSGeo4W QGIS python instance i.e.
py3-env
python -m pip install spyder
But this gives errors in the IPython console i.e.
SyntaxError: invalid syntaxFile "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
file=sys.stderr)
Thanks for any help.
_______________________________________________
Qgis-user mailing list
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
John Walker
2018-10-19 02:01:51 UTC
Permalink
Actually, I take that back. It doesn't seem to work in PyCharm after
further testing. I get the following error:

ImportError: DLL load failed: The specified procedure could not be found.

Not sure what to do now.
Post by John Walker
Thanks Luca,
That script is actually similar to the script contained
in C:\OSGeo4W64\bin\python-qgis.bat which I have been testing. When I open
a OSGeo4W Shell and execute that script and type 'import qgis.core' into
the python console, it has no issues. When I exit the python console
(pressing ctrl-z) and start spyder3 (which I pip installed previously) it
have no issues with 'import qgis', but it complains when I 'import
ImportError: DLL load failed: The specified procedure could not be found.
I read on
https://nathanw.net/2014/05/10/setting-up-pycharm-for-pyqgis-and-qt/ that
when you want to get PyCharm working with qgis, you need to change the
python interpreter in PyCharm. So I changed the python interpreter in
spyder to C:\OSGeo4W64\bin\python3.exe, and restarted the kernel. I now get
An error ocurred while starting the kernel
File "C:\OSGeo4W64\apps\Python36\lib\site.py", line 177
file=sys.stderr)
If however I execute PyCharm after running the
C:\OSGeo4W64\bin\python-qgis.bat script, and setting the PyCharm python
interpreter to C:\OSGeo4W64\bin\python3.exe, it works flawlessly. I guess
at this stage I will use PyCharm and abandon my efforts with getting things
working in Spyder, which will be a pain for me as I really love spyder.
Thanks again for your help.
Cheers.
Post by Nicolas Cadieux
Hi John,
If you figure this one out, can you poste the solution? I would like to
do the same thing.
Thanks
Nicolas
Hi, would anyone know how to configure Spyder to work with the QGIS
library? I am finding the python editor in QGIS difficult to work with
because it has no debugger and I cannot run highlighted code. I have tried
1. created a new conda environment and installed QGIS via conda using: conda
install -c conda-forge qgis. However I get errors when trying to import
qgis.core
2. installed Spyder within OSGeo4W QGIS python instance i.e.
py3-env
python -m pip install spyder
But this gives errors in the IPython console i.e.
SyntaxError: invalid syntaxFile "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
file=sys.stderr)
Thanks for any help.
_______________________________________________
Qgis-user mailing list
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
Loading...