How can I get the arcpy module to load in python 3.6?

35773
11
08-07-2017 07:45 AM
Highlighted
New Contributor III

import arcpy

Does not work in 3.6 python.  I really need to get it to work or it's new version.  Very new to Python.

It's odd, when I look at installed programs, it says I have 3.6 python.  Running Python in a command window says it's 3.6.

However, when I open IDLE, it says it's using Python 2.7.8. 

Bit out of my element.  I'm a VB/JScript programmer.

Thanks

11 Replies
Highlighted
MVP Esteemed Contributor

You have to use the python distribution that comes with ArcMap (2.7.x) or ArcGIS Pro (3.5.x).

You can spend a whole load of time trying to patch a solution which is fine if you have more time than needs.  The differences between 3.5.x and 3.6 or 3.7 won't manifest themselves as important for ArcMap or ArcGIS Pro.

Pro installs an Anaconda distribution which has been tailored to esri specifications.

I keep a separate Anaconda distribution (installed separately) for pure python work for 3.6/3.7 and associated models.

I would recommend you uninstall all versions of python, then install arcmap and ArcGIS pro... they will handle everything.  You can then setup your favourite IDE to use either, but Spyder is sweet for working with Pro

Highlighted
New Contributor III

I've ArcMap 10.3 and pro installed.  The python version is 3.6, as per 'Windows Programs and Features'

I'm a bit befuddled that if I just start a windows command window, launch python (says it's 3.6) and key in import arcpy, I get an error- ModuleNotFoundError: No module name 'arcpy'.

But if I launch IDLE, it says it's working in python 2.7.  And import arcpy works just fine.

You think reinstalling ArcMap and ArcPro will help?  That's kindof a pain.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

because IDLE is arcmap's default, since it is installed in the proper path.

I would upgrade ArcMap to 10.5.1 and install ArcPro 2.0 if you have an adequate machine and the ability to do so

Pro  http://pro.arcgis.com/en/pro-app/get-started/arcgis-pro-system-requirements.htm

ArcMap http://desktop.arcgis.com/en/arcmap/latest/get-started/setup/arcgis-desktop-system-requirements.htm

Then see my blog for several links on how to get Spyder as your ide... or you can use conda or pip to install others (and there are other links for others elsewhere)

PS  a clean install will entail removing all remnants of an esri or arcmap folder in your system after the install

Highlighted
MVP Esteemed Contributor

What is driving your Python 3.6 requirement?  The only way to run ArcPy safely with Python 3.x is by installing ArcGIS Pro, and ArcGIS Pro is currently bundled with Python 3.5.  If you absolutely have to run Python 3.6, you won't be running a supported platform, even if you can get it working.

Highlighted
New Contributor III

Aha.  I do have Arcpro installed (10.4.7), going to the install directory for python for ArcPro, and just running it in command line I can import the two modules I need.  It's Python 3.5.3.

This will work.  I assume I can launch python from within ArcPro?

I'll be gone for two days, but will keep an eye on this.

Thanks

Reply
0 Kudos
Highlighted
New Contributor III

Well, I thought it would work.  Both

import arcpy

from arcgis.gis import GIS

seem to work in python 3.5.3

At least the import command does not fail.

However the command
gis = GIS("http://summitcountyco.maps.arcgis.com/home/index.html", "UserName", "Password")

Throws a 404 error.  It does work however in python 3.6.

But import arcpy does not work in 3.6. "Can't find the module."

Am I gonna have to use two different versions of python?  Odd that arcpy does not work, I thought it was one of the most basic modules.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

I suspect that the previous installation is still lurking around.  As advised, it is best to remove previous installations of python and get a clean install of python and related modules.  If you want to use an IDE, then IPython and Spyder can be used... my blog post gives one example of setting up those IDEs so they can work as standalone applications and/or in conjunction with Pro

Reply
0 Kudos
Highlighted
New Contributor III

I have similar problems. After installed arcgis pro, got an error of ''unable to import arcpy'' but it was working okay before. The problem was solved after re-install arcmap. 

Highlighted
by
New Contributor

@LiranSun Did you re-install arcmap, or arcgis pro? I have ArcMap 10.7, which I believe comes with Python 2.7. I also have ArcGIS Pro 10.2.5.1 which comes with Python 3.6. I can import arcpy if I am configured to Python 2.7, but not if I am configured to 3.6. 

Reply
0 Kudos