Spyder: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
Spyder is an IDE for Python. I learned of it when working for Ceres Imaging.
Spyder is an IDE for Python. I learned of it when working for Ceres Imaging.
'''Go read the [[Anaconda]] page and set it up, then come back here.'''


https://github.com/spyder-ide/spyder
https://github.com/spyder-ide/spyder


For me there are three critical features, which it has:
For me there are 4 critical features, which it has:
* It includes a source level debugger.
* It includes a source level debugger.
* It is cross-platform.
* It is cross-platform.
* It has code completion.
* It has code completion.
 
* '''Installing it does not require admin rights on Windows''', so I have added it to my toolbox of portable Windows tools.
Installing it does not require admin rights on Windows, so I can use it everywhere.


It's unusual in that it opens an IPython interpreter as its console window
It's unusual in that it opens an IPython interpreter as its console window
so you can just type in random python there.
so you can just type in random python there. At Ceres we used it like a shell prompt to run code much like running commands.


== ArcGIS ==
== ArcPy ==


My primary interest is to debug code running on Windows using arcpy.
My initial interest in spyder was to debug code running on Windows using arcpy.
That means I have to use a 2.7 kernel. Does that mean installing arcpy in a different place
or getting spyder to use the Python that ESRI installs?


I think it's the same as in the Mac -- edit the configuration settings to tell it which Python interpreter to use.
First, get everything going with [[Anaconda]]. That means getting arcpy to import from a python prompt.
In the Mac I have to text edit ~/.spyder/spider.ini and change "Default" to "false" and "executable" to point at the right Python.
Maybe the preferences editor works in Windows?? It won't let me pick /usr/local/bin/python on the Mac, it ignores the change.


== Remote debugging ==
Install spyder into the Anaconda environment.


This is something I can do in Komodo, but I have not needed it in some time, so I have not tried it in Spyder yet.
To allow other Python installations to access Arcpy a file must be copied from the \Lib\site-packages\ folder within the Arc Python installation and placed in the corresponding folder of the non-Arc Python. If you have not installed 64-bit background geoprocessing the file is Desktop10.1.pth; if you have installed it, the file is DTBGGP64.pth.
Some notes: https://groups.google.com/forum/#!searchin/spyderlib/remote%7Csort:relevance/spyderlib/usljVmI50GI/BdjmwX1k4nAJ


I wonder if I could use a copy on my Mac to debug code running on a Parallels machine.
I copied the pth files into the 32-bit and 64-bit envs/arc1051*/Lib/site-packages folders as well as the top level site-packages


== Mac ==
It is likely NONE of this is needed with [[ArcGIS Pro]], just use the built in conda environment, and install spyder there.


Compared with Windows this is starting to seem difficult! I ran through several attempts before deriving the following.
To work with MDB (Personal Geodatabase) files requires working in a 32-bit space so I install Miniconda 32-bit + Python 2.7
just for those special occasions when I still need to use MDB files.


I could not find a combination of brew and pip commands that would give me a working spyder.
== Remote debugging ==


With Windows I found [https://conda.io/miniconda.html miniconda] worked, trying it on the Mac. The full "Anaconda" package is big and all I want is spyder!
This is something I can do in Komodo, but I have not needed it in some time, so I have not tried it in Spyder yet.
I grabbed the 2.7 python version, I like python 3 but most of the GIS stuff around seems to prefer 2.7.
Some notes: https://groups.google.com/forum/#!searchin/spyderlib/remote%7Csort:relevance/spyderlib/usljVmI50GI/BdjmwX1k4nAJ
At least in the ESRI world.


So download the shell script, run it, installing miniconda in your home directory.
I wonder if I could use a copy on my Mac to debug code running on a Parallels machine.
Change your path. Then you can run "conda install spyder".


This installs (yet another) Python environment. I do '''NOT''' put ~/miniconda2/bin into my system PATH.
== Mac install note ==
Instead I create symlinks as needed from ~/bin


  cd ~/bin
  cd ~/bin
Line 50: Line 44:
  ln -s ../miniconda2/bin/spyder
  ln -s ../miniconda2/bin/spyder


Since I have ~/bin on my path already this works. I can launch spyder 3 now.
Instead of trying to trick Spyder into using another Python, I just switched over to using Spyder for GIS
In spyder I can set the python executable. The default is "/Users/bwilson/miniconda2/bin/python". The "preferences" did not WORK.
and I install modules using "conda install ''modulename''", e.g. "conda install gdal" will install the latest gdal.
I had to edit ~/.spyder/spyder.ini directly and I set "executable" = "/usr/local/bin/python" and "Default=false".
 
You can use virtual environments, this will set one up called "gis" and
install all the modules that arcgis and gdal depend upon.


You can tell it worked by looking at the console in spyder (lower right). It should NOT say "Continuum" next to Python 2.7.13
conda create -n gis -c esri arcgis gdal


I think I sort of have it working, now I have to learn more about Spyder itself. That would be elsewhere in this page.
Now you have to tell spyder that you want it to use that virtualenv environment.

Latest revision as of 17:57, 25 July 2018

Spyder is an IDE for Python. I learned of it when working for Ceres Imaging.

Go read the Anaconda page and set it up, then come back here.

https://github.com/spyder-ide/spyder

For me there are 4 critical features, which it has:

  • It includes a source level debugger.
  • It is cross-platform.
  • It has code completion.
  • Installing it does not require admin rights on Windows, so I have added it to my toolbox of portable Windows tools.

It's unusual in that it opens an IPython interpreter as its console window so you can just type in random python there. At Ceres we used it like a shell prompt to run code much like running commands.

ArcPy

My initial interest in spyder was to debug code running on Windows using arcpy.

First, get everything going with Anaconda. That means getting arcpy to import from a python prompt.

Install spyder into the Anaconda environment.

To allow other Python installations to access Arcpy a file must be copied from the \Lib\site-packages\ folder within the Arc Python installation and placed in the corresponding folder of the non-Arc Python. If you have not installed 64-bit background geoprocessing the file is Desktop10.1.pth; if you have installed it, the file is DTBGGP64.pth.

I copied the pth files into the 32-bit and 64-bit envs/arc1051*/Lib/site-packages folders as well as the top level site-packages

It is likely NONE of this is needed with ArcGIS Pro, just use the built in conda environment, and install spyder there.

To work with MDB (Personal Geodatabase) files requires working in a 32-bit space so I install Miniconda 32-bit + Python 2.7 just for those special occasions when I still need to use MDB files.

Remote debugging

This is something I can do in Komodo, but I have not needed it in some time, so I have not tried it in Spyder yet. Some notes: https://groups.google.com/forum/#!searchin/spyderlib/remote%7Csort:relevance/spyderlib/usljVmI50GI/BdjmwX1k4nAJ

I wonder if I could use a copy on my Mac to debug code running on a Parallels machine.

Mac install note

cd ~/bin
ln -s ../miniconda2/bin/conda
ln -s ../miniconda2/bin/spyder

Instead of trying to trick Spyder into using another Python, I just switched over to using Spyder for GIS and I install modules using "conda install modulename", e.g. "conda install gdal" will install the latest gdal.

You can use virtual environments, this will set one up called "gis" and install all the modules that arcgis and gdal depend upon.

conda create -n gis -c esri arcgis gdal

Now you have to tell spyder that you want it to use that virtualenv environment.