Select to view content in your preferred language

Import arcpy into Jupyter Nootebook

23402
29
07-26-2017 02:22 AM
IonutAlixandroae4
Occasional Contributor

Hi,

I have 3 versions of Python installed on my machine, 1st (v 2.7) which came with ArcMap 10.5, 2nd (v 3.5) which came with ArcGIS Pro and 3rd (v 3.6) which came with Anaconda 3 (for using Jupyter Nooteboks). 

Now, in my notebooks I can use arcgis python API but I also want to use arcpy modules from ArcGIS Pro. Is there a workflow for this setup or some steps to take ?

Thanks,

Ionut

29 Replies
curtvprice
MVP Esteemed Contributor

An easier way is to simply install the Python API using ArcGIS Pro's python package manager as explained here https://developers.arcgis.com/python/guide/install-and-set-up/#Install-using-ArcGIS-Pro

This only works if you have administrative access to the machine. These definitely more complicated instructions allow you to use a per-user (ie no admin required) Conda setup that is entirely independent of ArcGIS. 

LefterisKoumis
Regular Contributor II

I spent numerous hours trying to figure out why I couldn't install my packages (like arcgis) using the ArcGIS Pro python package, only to find out that I had to disable the security first. So, in python commnad window type:

  • conda config --set ssl_verify false

Then you will have no problems.

0 Kudos
curtvprice
MVP Esteemed Contributor

in python command window type:

conda config --set ssl_verify false

Then you will have no problems.

This is highly discouraged as it is a serious security risk, by passing https requirements set up by your organization. Better to set up a SSL certificate or use ssh authentication.

0 Kudos
LefterisKoumis
Regular Contributor II

In my case working in an intranet environment, that's not an issue. You can just turn the ssl off temporarily, add the packages, and then turn it on back on.

0 Kudos
curtvprice
MVP Esteemed Contributor

It doesn't sound very "intranet" if you can connect to the Conda repository.

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

I am just curious why you need to use ArcPy in notebook at the first place, by my understanding, ArcPy is a local API which is best to run inside of ArcGIS desktop products like Pro, ArcMap, ArcCatalog even some stand-alone scripts. While notebook and ArcGIS API for Python is a good technical combination for Portal/ArcGIS Online which basically supports the rest API...

Sorry, I know this is rather a comment than a practical solution.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Uses?

prototyping... teaching... many uses and it is not restricted to making maps.

Some examples and background and check the discussion ipnb and pdf there 

Notebooks exist for R and Julia etc making a sort of one-interface option without the fluff of a full-fledged IDE

Arcpy is also embedded within the ArcGIS module in fact, if you don't have arcpy, you can still work with geometry since they expose access to shapely, and use Pandas for attribute access and processing.

Sadly, it still isn't incorporated into geonet, which would be nice, allowing people to test python code (for instance) with their own data online and maybe within a question thread

0 Kudos
LefterisKoumis
Regular Contributor II

The jupyter notebook is the best IDE that it's available for developing/troubleshooting python scripts. Also you can easily modify existing geoprocessing tools in notebook to create REST services to be used in custom web apps. I don't even use Portal/ArcGIS Online. 

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

I am very new to Jupyter Notebook, and I wrote less than 10 lines of code in it, so what I am saying is limited to my own knowledge.

I have to admit it looks amazing, it works like a magic with some executable code in a nice technical article. but I am not sure it's the best python IDE if it is an IDE at all. For me, Notebook is for presenting not for developing. I have a little more experience with PythonWin, PyScripter and WingIDE, I find these IDEs provide a developer far more powerful debugging tools. I may use notebook to document some of my python tools for ArcGIS Online and Portal.

additionally, I see Notebook as an ideal terminal to interact with web services that return tables, charts, images or maps that can be easily rendered in a browser, as the cmd window to many locally installed applications.

Thanks for any input to this discussion, I am learning...

0 Kudos
DanPatterson_Retired
MVP Emeritus

check out 'spyder' is you are using ArcGIS Pro.  And you can use IPython separately as well (my blog has a few posts)

0 Kudos