Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

Unable to import arcrest in arcgis pro #243

Closed CTLocalGovTeam closed 8 years ago

CTLocalGovTeam commented 8 years ago

@MikeMillerGIS

ArcRest v3.5.3

Bug

Repro Steps

  1. Install ArcGIS Pro for Python (ArcGIS Pro 1.2)
  2. Run setup.py install in ArcREST src directory using Pro's Python. This will install ArcREST to Python34.
  3. Use a gp tool with a script importing ArcREST
  4. Run tool in ArcGIS Pro
  5. Observe it fails to run with import error

image

achapkowski commented 8 years ago

@CTLocalGovTeam - Can you do the following from your Pro Python Windows:

import sys
print(sys.path)

Example output:

['c:\\program files\\arcgis\\pro\\Resources\\arcpy', 'c:\\program files\\arcgis\\pro\\bin\\Python\\DLLs', 'c:\\program files\\arcgis\\pro\\bin\\Python\\lib', 'C:\\Program Files\\ArcGIS\\Pro\\bin', 'c:\\program files\\arcgis\\pro\\bin\\Python', 'c:\\program files\\arcgis\\pro\\bin\\Python\\lib\\site-packages', 'c:\\program files\\arcgis\\pro\\Resources\\ArcToolbox\\Scripts', 'c:\\program files\\arcgis\\pro\\bin', 'C:\\Python34\\Lib\\site-packages']

Then see if ArcREST was installed in one of those paths? Do you have more than one version of Python installed on your machine? If so, are you sure you are using the correct python.exe?

Thanks

CTLocalGovTeam commented 8 years ago

@achapkowski

sys.path outputs this:

['', 'c:\\Python34\\python34.zip', 'c:\\Python34\\DLLs', 'c:\\Python34\\lib', 
'c:\\Python34', 'c:\\Python34\\lib\\site-packages', 'C:\\Program Files\\ArcGIS\\Pro\\bin', 
'C:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcPy', 
'C:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcToolBox\\Scripts']

ArcREST was installed to 'c:\Python34\lib\site-packages' I can even import ArcREST on the commandline, but not in Pro

image

I do have python27 installed and it also has ArcREST installed and works fine in ArcGIS Desktop.

CTLocalGovTeam commented 8 years ago

@achapkowski

Update: When I imported ArcREST in commandline, it took a good 10 seconds to import. Then I restarted Pro and importing ArcREST works now! Maybe Pro needed a restart after installing ArcREST to site-packages

But now, I cannot import arcresthelper

image

achapkowski commented 8 years ago

@CTLocalGovTeam can you pull the latest version and run the setup.py again?

CTLocalGovTeam commented 8 years ago

@achapkowski Uninstalled ArcREST 3.5.3 using pip. It just deleted the egg info. Then manually deleted the arcrest and arcresthelper directories from site-packages.

Pulled ArcREST from master and when i try to run setup.py, it complains.

image

MikeMillerGIS commented 8 years ago

What files/folders are in the SRC folder?

Sent from my Verizon Wireless 4G LTE DROID

CTLocalGovTeam commented 8 years ago

@achapkowski

Finally, got it to work! CDed into the src directory and ran setup.py from there. Will post an update if i run into any issues further. Thank you for helping.

sharpering commented 7 years ago

@CTLocalGovTeam sorry that I have to open this thread again, but I have some difficulties using arcrest in ArcGIS Pro.

I have done the same steps as you have done... I have CDed into the src directory and ran setup.py from there, but when I want to use arcrest in ArcGIS Pro it always says that the module arcrest cannot be found.

I printed out the sys.path and copied the two folders "arcrest" and "arcresthelper" to "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages" manually. After doing so another error message appears:

image

I think the problem is the syntax. The scripts are written in 2.7 but Pro is using 3.x.

Any ideas?

MikeMillerGIS commented 7 years ago

You need to use the most recent version in master. The version you have used a python 2.7 format for catching exceptions. This does not work in 3. These have been removed in master.

Here is line 43 in web/_base. - https://github.com/Esri/ArcREST/blob/master/src/arcrest/web/_base.py#L43

sharpering commented 7 years ago

Thanks a lot :), that was the solution for this error. I am still wondering why I have to change one python script (_base.py) manually. I downloaded the last version (ArcRest 3.5.3) and I thought that such a problem would be adressed :).

After fixing this problem another error is showing up. It is the same as mentioned above by @CTLocalGovTeam:

image

As you can see in the following picture, there is a file "common.py":

image

Is it maybe possible that I work with an old version? If I try to run for example "Delete Data from Feature Servcie" I get the following error in ArcGIS Pro:

image

MikeMillerGIS commented 7 years ago

ArcRest will work with py 3.x. ArcRest Helper was never completely converted. You can preform your script with just ArcRest.

You will have better luck with the code in master branch.

MikeMillerGIS commented 7 years ago

I am back next week and can take a look at why the import is failing.

MikeMillerGIS commented 7 years ago

I just tried with version in Master and the import works fine. I would remove the ArcRest and ArcRestHelper folders from your python folder and manually copy them back from master.

this works in python 3.x import arcrest from arcresthelper import securityhandlerhelper config = {'username': 'UserName', 'password': 'Password'} token = securityhandlerhelper.securityhandlerhelper(config) print (token.securityhandler.token)

sharpering commented 7 years ago

Thanks for the hint :). I removed all files from ArcRest and started a new installation. The import of arcrest and arcresthelper works fine now, but when I want to use the tool "Remove Data from Feature Service" I get some error messages. I have logged the messages / errors with Issue #317 and Issue #318.

I imported the Toolbox from the Master folder and I have tested this tool in ArcGIS Pro 1.3 and 1.4.

MikeMillerGIS commented 7 years ago

If you can submit a PR with the fix, that would be great.

sharpering commented 7 years ago

Done :)