Anybody has luck with import arcpy in 10.5.1?

4185
18
10-13-2017 04:43 AM
RajuGopinath1
New Contributor II

The import arcpy doesn't work in 10.5.1 ArcGIS Desktop installation of python 2.7.13. Anybody in the same boat?

I have both ArcGIS Server and Desktop installed in this machine. But, default python is 32 bit one. The pth variables and environment variables are all good (as it works fine in a Desktop 10.3 installation with same configuration). I even run a repair on this installation. Nothing works.

Here is the error which I get on running import arcpy:

H:\>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.executable
C:\Python27\ArcGIS10.5\python.exe
>>> import arcpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\__init__.py", line
 20, in <module>
    import numpy
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\__init__.py", line 187, i
n <module>
    from . import add_newdocs
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\add_newdocs.py", line 13,
 in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\lib\__init__.py", line 18
, in <module>
    from .polynomial import *
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\lib\polynomial.py", line
19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\linalg\__init__.py", line
 51, in <module>
    from .linalg import *
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\linalg\linalg.py", line 2
9, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: DLL load failed: The specified path is invalid.
>>>

I initiated a tech support case with ESRI and they don't have anything new to contribute as they think that it's a bug. So, they transferred my case to Desktop team from where I am waiting for a response. Meanwhile, I thought of posting it in the community to see whether anybody has luck with solving this issue?

Tags (1)
0 Kudos
18 Replies
VinceAngelo
Esri Esteemed Contributor

The PATH (system environment variable) needs to change with release, since the version number is part of the name with the site package. sys.path is assembled from PATH and site package loading instructions. I prepend C:\Python27\ArcGIS10.n; or C:\Python27\ArcGISx6410.n; to PATH in the cmd.exe window or shell script (where n is the installed release)

 - V

0 Kudos
DanPatterson_Retired
MVP Emeritus
PythonWin 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> import sys
>>> import numpy as np
>>> sys.path
['', 'C:\\ArcPro\\Resources\\ArcToolBox\\Scripts', 'C:\\ArcPro\\Resources\\ArcPy',
'C:\\Git_Dan', 'C:\\WINDOWS\\SYSTEM32\\python27.zip', 'C:\\Python27\\ArcGIS10.5\\DLLs',
'C:\\Python27\\ArcGIS10.5\\lib', 'C:\\Python27\\ArcGIS10.5\\lib\\plat-win',
'C:\\Python27\\ArcGIS10.5\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.5\\Lib\\site-packages\\pythonwin',
'C:\\Python27\\ArcGIS10.5', 'C:\\Python27\\ArcGIS10.5\\lib\\site-packages',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\bin', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\ArcPy',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\ArcToolBox\\Scripts', 'C:\\Python27\\ArcGIS10.5\\lib\\site-packages\\win32',
'C:\\Python27\\ArcGIS10.5\\lib\\site-packages\\win32\\lib']
>>> 

I have Pro and arcmap installed, so just ignore the c:\arcpro folders

Compare to yours

Notice import numpy worked just fine

0 Kudos
RajuGopinath1
New Contributor II

Thanks Dan. All the path variables looks fine compared to yours:

H:\>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (
Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'E:\\Python_Modules', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\
\ArcGIS10.5\\DLLs', 'C:\\Python27\\ArcGIS10.5\\lib', 'C:\\Python27\\ArcGIS10.5\\
lib\\plat-win', 'C:\\Python27\\ArcGIS10.5\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10
.5', 'C:\\Python27\\ArcGIS10.5\\lib\\site-packages', 'C:\\Program Files (x86)\\A
rcGIS\\Desktop10.5\\bin', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\ArcPy',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\ArcToolBox\\Scripts']


Do you see anything which I overlooked?

0 Kudos
HåkonDreyer
Esri Contributor

What is in the e:\Python_modules folder?

0 Kudos
RajuGopinath1
New Contributor II

That's a custom Python module

0 Kudos
NathanJennings
New Contributor III

Did you receive any resolution on this?  I have almost the exact same problem.

I had Anaconda installed to help someone with a script outside of ArcGIS.

I uninstalled Anaconda.  This did't help.

I completely uninstalled 10.5.1 and reinstalled.  This did not solve my problem.

My sys.path shows this:

>>> sys.path
['', u'c:\\program files (x86)\\arcgis\\desktop10.5\\arcpy', 'C:\\WINDOWS\\SYSTEM32\\python27.zip', 'C:\\Python27\\ArcGIS10.5\\DLLs', 'C:\\Python27\\ArcGIS10.5\\lib', 'C:\\Python27\\ArcGIS10.5\\lib\\plat-win', 'C:\\Python27\\ArcGIS10.5\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.5', 'C:\\Python27\\ArcGIS10.5\\lib\\site-packages', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\bin', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\ArcPy', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.5\\ArcToolBox\\Scripts']
>>>

When I do import numpy, I see this problem

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\__init__.py", line 187, in <module>
    from . import add_newdocs
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\core\__init__.py", line 9, in <module>
    from . import numerictypes as nt
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\core\numerictypes.py", line 968, in <module>
    _register_types()
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\core\numerictypes.py", line 965, in _register_types
    numbers.Integral.register(integer)
AttributeError: 'module' object has no attribute 'Integral'

Any help or insight from anyone, is greatly appreciated.

I do have ArcPro 2.0.1  Both Desktop and Pro were running fine.  I don't think I "unchecked" the correct boxes for Anaconda, but with a full uninstall/re-install of ArcGIS 10.5.1, I thought this would solve my problem, but it did not.  I do see that I still have the C:\Python27\ArcGIS10.4 folder still around, since I originally upgraded in place 10.5.1.

Thank you for any assistance or insight.

UPDATE:  I deleted the ArcGIS10.4 folder, I completely uninstalled 10.5.1.  I reinstalled the 10.5.1 software,  took all of the defaults for the install.

I made sure before I reinstalled, that Python was not on my system.

I can type in Python at a CMD window and type in import numpy, import arcpy.  A prompt returns, no problem.

When I write a simple script in the IDLE window with 

print "test"

import arcpy

print "this is a test"

The first line is printed in the shell, then I get an error that the import arcpy line doesn't work.  See the errors below.

If I use CMD to bring up a prompt, then type in "python" to get a python prompt and type in 

print "test"

test (is printed)

import arcpy (prompt is returned)

print "this is a test"

this is a test (is printed)

I also tested within ArcMap using the Python window and did a Buffer.  The buffer was successful using the Python window.

I am really not sure what is/could be going on.

I believe I have only one installation of Python (the 2.7.13 that comes with the ESRI 10.5.1 install).

Traceback (most recent call last):
  File "C:\temp\junk4.py", line 8, in <module>
    import arcpy
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\__init__.py", line 20, in <module>
    import numpy
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\__init__.py", line 187, in <module>
    from . import add_newdocs
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\core\__init__.py", line 9, in <module>
    from . import numerictypes as nt
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\core\numerictypes.py", line 968, in <module>
    _register_types()
  File "C:\Python27\ArcGIS10.5\lib\site-packages\numpy\core\numerictypes.py", line 965, in _register_types
    numbers.Integral.register(integer)
AttributeError: 'module' object has no attribute 'Integral'

I also noticed this....

I had part of a simple script I wrote to demonstrate how to work with numbers.  I called this script numbers.py and saved it in my "c:\temp" folder.

When I posted my error messages above, the results of my numbers.py script were showing up and I could not figure out why.

After running this script (or when re-installing ArcGIS and the 2.7.13 version of Python, I noticed that a numbers.pyc file was also created in c:\temp.  I did not create the .pyc file.

As a test, I renamed both the numbers.py and numbers.pyc files to numbersx.py and numbersx.pyc.  

When I reran my scripts, they all worked!

I even did an independent test with a simple numpy script from here:  https://docs.scipy.org/doc/numpy-dev/user/quickstart.html to test the use of the numpy module.

A script using seems to work.  I tested a script using the buffer routine to test the use of the arcpy module.  This seems to work.

I am not sure why having a script I wrote, called numbers.py in the c:\temp folder should matter, but it does.

I did see that there is a numbers.py file in the C:\Python27\ArcGIS10.5\Lib which relates to the functioning of Python, so I am guessing that the file I created in my temp folder was causing the problem.  If anyone has any insight on this, please share.

I guess, I will be more careful with naming my python scripts.  I was using what I thought was simple names so others newer to Python could use my scripts to learn.

The teacher continues to learn, too.

Thank you,

Nate

0 Kudos
RajuGopinath
New Contributor III

Hi Nate:

I got it resolved. I did so many reinstalls of python (which could have avoided- just trial and error) as I mentioned before. But, I think what the real issue was- user permissions and default directory path (I am using windows). My suggestion is to give full privileges (at least edit or update)  generously to all folders which has python installation and which python uses like:

C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\

C:\Python27

...and any user/script folders

Default drive path was creating additional issues for me as it was defaulting to network drive due to our company domain policy. To check this, open your comand prompt and see whether the initial path is pointing to your local drive or to your network drive home folder. If it's pointing to network drive, that will be your problem.

To point it back to local drive, I found that a small registry hack will help. Adding a string value “AutoRun” with data “C:” in HKEY_CURRENT_USER\Software\Microsoft\Command Processor will fix that issue.

Also note that: changing the Autorun value may mess up Node run parameters, if you're using Web App Builder Dev edition. I had to use Python Http server instead of node in my local machine for development purpose after this registry fix.

0 Kudos
StevenHaymes1
New Contributor

Why is your path to Python C:\Python27\ArcGIS10.5\?  I have never seen that before. Also, I NEVER let ArcGIS install Python.  Since I do more Python development outside of ESRI than inside, I do the standard Python installation and not the ESRI Python installation.  I recommend the following:

1st clean everything up:

1.  Uninstall all Python site-packages like NumPy.

2.  Uninstall Python.

3.  Uninstall all related ESRI software.

4.  Check directories to see that the uninstalls are clean.

5.  Check your path and remove all paths to Python.

2nd reinstall everything:

1.  Install 32 bit Python 2.7.n where n is probabably 13 or 14 now.

2.  Install the NumPy and other site packages with pip which is the built-in Python site package installer.

3.  Check that you path is properly set for Python.

4.  Check that Python will work at the command line and with a test program such as helloworld.py and also try to import NumPy and other site packages

5.  Install the ESRI software with Python unchecked so another version of Python is NOT  installed.

6.  Test Python in ArcGIS.

This should work.

MichaelMixon
New Contributor II

I had a similar issue after installing Pro on my machine.  Having both Pro and Desktop on the machine has caused me lots of grief.  The link below may help you with your issue.

https://gis.stackexchange.com/questions/178693/using-arcpy-with-arcgis-pro-and-arcgis-desktop-on-sam...

0 Kudos