How to run python with the ArcGIS Pro 1.4 from outside

5137
37
Jump to solution
03-13-2017 04:00 PM
Highlighted
New Contributor II

With ArcGIS Desktop, version 10.4 for example, I installed the Anaconda Python and was able to run all the arcpy scripts from outside of the ArcGIS session (for example with Spyder, or Jupyter Notebook) with the following Desktop10.4.pth file created in site-package with following three lines of code

C:\Program Files (x86)\ArcGIS\Desktop10.4\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.4\bin
C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcToolbox\Scripts

I want to replicate the same behaviour with the new ArcGIS Pro 1.4, but there seems no help on how to do this. I want to know how to do this with the Anaconda Python that is installed by default with ArcGIS Pro 1.4. Do I need to install a separate copy of Anaconda Python?

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Regular Contributor

Phil,

Yes, there's one additional step I neglected. You'll need the ArcGIS Pro bin directory to be registered as part of the path that Pro sees. You can do this a few ways, perhaps the simplest is to add it to your global path (C:\Program Files\ArcGIS\Pro\bin). If you'd rather not modify the global path, you can also add it to the lib\site.py file for the environment you created, or add another pth file, let's call it ArcGISProBin.pth:

import os; import sys; d = r'c:\Program Files\ArcGIS\Pro\bin'; os.environ["PATH"] = r"{};{}".format(d, os.environ["PATH"])

This is still a pain point and something we expect to improve in the near future.

Thanks,
Shaun

View solution in original post

37 Replies
Highlighted
MVP Esteemed Contributor

A quick run of sys.path yields for mine running python 3.5

 'C:\\ArcPro\\Resources\\ArcToolbox\\Scripts',

 'C:\\ArcPro\\Resources\\ArcPy',

 'C:\\ArcPro\\bin\\Python\\envs\\arcgispro-py3',

 'C:\\ArcPro\\bin',

plus personal ones and others that were from imports

you can set up icons on the desktop to run

C:\ArcPro\bin\Python\Scripts\proenv.bat   then type spyder    I usually right-click and get to 'run as administrator' to get it to go.

or set up a desktop shortcut to run spyder directly (again sometimes run as administrator is needed)

C:\ArcPro\bin\Python\envs\arcgispro-py3\Scripts\spyder.exe

Then I link spyder to PRO from the project window like so.

I keep a separate Anaconda distribution to run python 3.6+ with the scipy stack but no access to arcpy so I can work outside that environment

I have a couple of blog links , here is one if you are interested python and siblings with and without an arcmap environment

Highlighted
New Contributor II

Thank Dan. So based on your response, there is no way to replicate the old ArcGIS Desktop 10.4 arcpy behavior with the new ArcGIS Pro 1.4. With older setup, I just installed Anaconda Python with all its goodies and updates and just inserted a path to arcpy, and everything worked like charm. Even updating the newer version of Numpy, Matplotlib created no issues. 

Even though the Pro document says, its comes pre-installed with conda, it seems pretty restrictive. I haven't been able to figure out how to run Ipython/Jupyter notebook.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

No.. the conda distribution for Pro has all that stuff and more including the ability to install other packages easily.  Check out my blog links.  When you install pro, you get the a nice  conda distribution with the ability to run everything... here is

an image of the packages when you go to the Project window

Highlighted
MVP Esteemed Contributor

I'm just starting to install and test this myself, but at the Dev Summit it looked as if it could still be run outside of Pro.  I think that is how they did most of the demos.

Check out Install and set up | ArcGIS for Developers    You may need to log in to access.

So far (before I left work yesterday), I just added the package as Dan mentions.  I'm not sure if you IT will allow me to use it as a standalone, but I am also looking into that.  I know the "try it in the sandbox" seemed to be blocked on our network.  Just in case you see issues with that too.

Reply
0 Kudos
Highlighted
New Contributor II

Hi Dan_Patterson I checked your blog on Anaconda, Spyer and ArcGIS PRO. I was able to follow some parts but not everything. I think things has changed in the new PRO 1.4 since this blog.

So anyway thats my confusion, since new ArcGIS PRO 1.4 already comes with conda/anaconda, along with the ability to add more packages, I want to make this one work for all my workflow without having to install additional copy of Anaconda Python on my system. With the requirement of 32-bit Python 2.7 for ArcGIS Desktop, its already a mess. 

Specifically, I am unable to launch Jupyter notebook. Previously, with I was able to run this smoothly, now this does not work. Actually I think I have not been able to set this up. Before I try on my own and break something I was hoping that if someone has done this, I can follow your advice.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

Bidhyananda Yadav    I'm also having issues getting it to run the way I thought it would. 

Yesterday, I followed the instruction to add the arcgis API using the Python tab in ArcGIS Pro (as Dan describes and Install and set up | ArcGIS for Developers ). 

Then I was trying to run the shortcut created for "Jupyter Notepad (arcgisPro-Py3)" that was created in my "C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit)"  (and was located in the Start Menu for Anaconda) but it was just opening and closing right away.  It looks as if the Target for the shortcut has an error or is truncated.  The Target for the shortcut on my machine, after the path to the python.exe, ends with "C:       that is, a double quote at the start, but not a closing double quote.   I'm not sure what the full Target argument is supposed to be, as I let ArcPro 1.4 add is to the default location.  I'm not sure if that is a bug or not.  (??)

So I opened the Python command prompt in Pro and tried to   "conda install -c esri arcgis" and a few others, and keep getting "parsing error  SyntaxError:invalid syntaqx (<string>, line 1)".

Then I tried following the install instructions found Jupyter Notebook  for the API, and installed Anaconda from the .exe as instructed.  I'm keeping the "Register Anacaonda as my default Python 3.6" checked, however, since I do most of my development in 2.7 and Wing IDE, I may need to change things back (??).

That also does not seems to be working for me, and it doesn't look like Anaconda is showing in my path (may need to reboot after closing this comment).

I'm going to call in a tech support ticket and will let you know if I find out anything.

Reply
0 Kudos
Highlighted
Regular Contributor

Rebecca,

The issue with the shortcut not working is a bug, and I see that a bug has been filed with its description. You can still run the notebook from the environment prompt, but that is annoying that the shortcut isn't working directly.

When you said that you opened up a "Python command prompt", do you mean the Python window that's included within Pro? The error you're getting makes it look like you're at a Python interepreter prompt, which would cause that issue. To install the ArcGIS API for Python, instead you'll want to run the shortcut in the Pro group called "Python command prompt", then run the command you included.

You shouldn't need to install another Anaconda, it'll probably make things more complicated than necessary -- you can also use the Python backstage from Pro (Project > Python) to install the API without having to use any command line tools at all.

Cheers,

Shaun

Highlighted
MVP Esteemed Contributor

Shaun Walbridge Thanks for the info on BUG-000103143.     Because I figured out that something was wrong with the shortcut, that was why I installed the Anaconda process. 

Bidhyananda Yadav The step I was messing up in BOTH the Anaconda and the Pro install was trying to run the

conda install -c esri arcgis

from the wrong location. (I has used the "Python Package Install" In Pro, and it appeared to work, but needed this step). I kept trying to run the command within the "jupyter notebook" or as Shaun pointed out, from the Pro Python interpreter prompt, which I was incorrectly calling the Pro Python command prompt.  Once I ran it from the correct locations, the notebook worked as expected.

In short, for others that see this...

  • If installing using Pro (and not anaconda), (I think you stil need to install the arcgis python api package from within Pro first):
    • open Start->All Programs->ArcGIS->ArcGIS Pro->Python Command Prompt     (
      • you may want to open "As Administrator", although I didn't need to
    • run the install command above  (should only need to do once).
    • once the install finishes, in the same window, test if it worked by typing "jupyter notebook" at the prompt and give it time to open in a browser. 
    • To further test, in the Jupyter Notebook that opens, type the line below and run (there is a button in the toolbar) to make sure you do not get an error.
      from arcgis.gis import GIS
    • If all that works, it is good to go and I suggest trying some of the samples.
    • Because it seems to open in the folder that you start the session, you may want to change that location with   "cd \<path>" before starting the notebook, and eventually work with a copy of the shortcut for the Python Command Prompt to make it easier.
    • To close, it seems you just have to close the tab in the browser, and then the command prompt (if anyone sees a smoother process, I'm interested)
  • For the Andaconda, external install, I follwed the instructions to download and install Anaconda, and like the above, I was using the wrong command prompt.  Instructions are the same as above, except the command prompt for me is:
    • Start->All Programs->Anaconda3 (64-bit)->Anaconda Prompt

Sample, using the Anaconda Prompt (Other prompt is similar)...I had already installed

I think if I have used the correct "ArcGIS Pro -> Python Command Prompt" (not the Python Interpreter within Pro) to do the "conda install -c esri arcgis" and to open the Jupyter Notebook, I think all would have worked fine without installing the Anaconda version.  It does run the notebook in the browser, i.e. external to Pro, so if I was to start over (which I will on another machine), I would start with just that process to see if it all works.

Hopefully this works for you too.  I see lots of potential in the Python API. 

BTW - I think the  Install and set up | ArcGIS for Developers needs to be a little more specific re: the  proper "Command prompt" ....with the paths and/or a pic, like I have above.  That would have saved me a lot of time (and was quickly pointed out by tech support this morning!)

EDIT: additional note.  When I used the Pro ->Python -> Add Packages and install the "arcgis" for the first time, it still installed the 0.3 beta version (3/14/2017).  I didn't notice that it was in the "Update Packages" list for a couple hours.  You should make sure to update it there tot he 1.0.1 (or above) version if yours loads the beta.

Highlighted
Regular Contributor

Rebecca,

Thanks for the details on your approach. Note that we also have an open bug on the unintuitive lack of "automatic refresh" issue you mentioned. We initially wanted to ensure that no remote request was made unless explicitly requeste by the user, but overall I think this is more likely to cause problems as you mentioned.