Select to view content in your preferred language

arcpy import error in cloned env

5467
14
Jump to solution
08-09-2022 11:20 AM
PhilipWhite1
New Contributor III

Hello,

I'm working on setting up an environment that can work with Spyder 5 and ArcGIS Pro. I'm on a fresh installation of 3.0. I have cloned the default environment in the new Package Manager, and it is named arcgispro-spy5. I created this clone so I can install Spyder in the cloned environment. When I attempt to import arcpy, I get this error:

 

 

(arcgispro-spy5) C:\Users\phwh9568\AppData\Local\ESRI\conda\envs\arcgispro-spy5>python
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arcpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 77, in <module>
    from arcpy.geoprocessing import gp
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from ._base import *
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 14, in <module>
    import arcgisscripting
  File "C:\Users\phwh9568\AppData\Local\ESRI\conda\envs\arcgispro-spy5\lib\site-packages\arcgisscripting\__init__.py", line 131, in <module>
    from ._arcgisscripting import *
ImportError: DLL load failed while importing _arcgisscripting: The specified module could not be found.

 

 

I get this whether I do it in the command prompt or from Spyder. But, if I switch the environment in my command prompt back to the default arcgispro-py3 environment, I'm able to import arcpy just fine.

What is going on here? Does anyone have guidance on how to correct this?

Thanks,

Phil

Tags (2)
0 Kudos
14 Replies
ShaunWalbridge
Esri Regular Contributor

Great, glad you figured this out! As Luke suggested, conda-forge should work for most cases where you are adding specific packages. The two steps I'd recommend are:

1. Start with the Pro default cloned environment (as you did) either from the UI or the command line with:

 

conda create --clone arcgispro-py3 --name spy --pinned

 

The --pinned flag is helpful here because it requests that the packages we ship won't be removed from the environment and the versions will match what Pro includes.

2.  When installing the package from conda-forge, use the conda-forge::package syntax or specify -c conda-forge just for the command being used as Luke mentions. For example:

 

(spy) C:\envs\spy> conda install conda-forge::spyder

 


Adding broader compatibility for conda-forge is a longer term goal, but it does become tricky at the binary level for shared C libraries which sit underneath the Python dependencies.

Cheers, Shaun

colpittJack
New Contributor II

Hi Everyone, 

I'm getting the same error in the original post, but after I install pyqt.

I've cloned my env using 

 

conda create --clone arcgispro-py3 --name arcpy3clone --pinned

 

-importing arcpy works fine....then...

-installed pyqt via

 

(arcpy3clone) C:\envs\arcpy3clone> conda install -c conda-forge pyqt

 

 then the error happens when I try to import arcpy again. I also tried some workarounds by installing pyqt to a clone env via arcgis pro. Also! this cloned env can import arcpy within arcgis notebooks in pro, but not pycharm. interesting stuff.

any advice is much appreciated!

**EDIT, problem solved by using pip installation instead of conda. 

GerryGabrisch
Occasional Contributor III

I have the same issue but I get this at the command line:

conda config --remove channels conda-forge
'conda' is not recognized as an internal or external command,
operable program or batch file.

0 Kudos
ShaunWalbridge
Esri Regular Contributor

You'll need to first activate conda, either by using the Python Command Prompt session, or by changing directory to the <install>bin\Python\Scripts path.

Cheers, Shaun

0 Kudos
Luke_Pinner
MVP Regular Contributor

Or

  • adding <install>bin\Python\Scripts (e.g. C:\Program Files\ArcGIS\Pro\bin\Python\Scripts) to the PATH user environment variable.
  • using <install>bin\Python\Scripts\conda config --remove channels conda-forge
0 Kudos