4

I would like to obtain the version of ArcGIS API for Python for logging/diagnostic purposes.

Is there a way to determine this before a connection is made?

I know that once I have the GIS object, I can obtain the version but I seek a way to obtain that information earlier in the script.

3
  • Your question is not quite clear. You're asking about the version of the ArcGIS API for Python, but from context, it seems you are interested in finding the version of the portal you are connecting to (this is what you get from the GIS object). Can you clarify? Commented May 22, 2019 at 3:52
  • No, this question is for the API itself. So your comment on @raskar-kapak's answer is actually the answer I was after. Which I thought I had tried and received None, but it is working this morning so I must have had a typo or something. If you modify your answer (which I think makes some good points for future readers of this q&a) with your comment, I'll accept it. Commented May 24, 2019 at 12:01
  • And the use case for this would be to when I provide a script to the customer and it doesn't work on their machine for some reason, I'll know what version API they are running from the log file. Commented May 24, 2019 at 12:02

2 Answers 2

8

Update based on OP's comment:

To get the version of the ArcGIS API for Python package, the following snippet should work without first establishing a connection:

import arcgis
arcgis.__version__

on my machine outputs

'1.5.2'

looks like I need to upgrade

If you wish to find the version without even importing arcgis at all, Raskar Kapak's answer would be a good choice.

If you are looking for the version of the portal you are going to connect to, you can't really know it before connecting. But you can make a connection with a less heavy package than arcgisand without authenticating against the portal. You would simply use any library of your choosing that can make a POST request. If you make a POST request with the parameter f=json against the URL <portalurl.com>/sharing/rest, you will receive the following JSON response indicating the portal version:

{"currentVersion":"7.1"}
2

The following code is working perfectly for me.

import pkg_resources

dists = [d for d in pkg_resources.working_set]
for el in dists:
    if "arcgis" in str(el):
        arcVersion=str(el).split(" ")[1]
print(arcVersion)

Hope it helps. Cheers.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.