Select to view content in your preferred language

Import arcpy problems

4704
4
03-11-2016 03:48 PM
forestknutsen1
MVP Regular Contributor

So, I recently got a new machine and I am having some frustration importing arcpy. It works fine in PyCharm but does not work when run from the command line.

An import test in IDLE:

From the command line:

IDLE is pointing to the wrong install of python:

PyCharm is pointing to the right location which I set:

I have set the PYTHONHOME to the ArcGIS location:

C:\Program Files (x86)\Python27\ArcGIS10.1 but this makes python not work at all in the cmd.

I have also tried setting the PYTHONPATH sys values as:

C:\Program Files (x86)\Python27\ArcGIS10.1

C:\Program Files (x86)\Python27\ArcGIS10.1\DLLs

C:\Program Files (x86)\Python27\ArcGIS10.1\lib

C:\Program Files (x86)\Python27\ArcGIS10.1\lib\plat-win

C:\Program Files (x86)\Python27\ArcGIS10.1\lib\lib-tk

C:\Program Files (x86)\Python27\ArcGIS10.1

C:\Program Files (x86)\Python27\ArcGIS10.1\lib\site-packages

C:\Program Files (x86)\ArcGIS\Desktop10.1\bin

C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy

C:\Program Files (x86)\ArcGIS\Desktop10.1\ArcToolbox\Scripts

I have also SET PATH=%PATH%;C:\Program Files (x86)\Python27\ArcGIS10.1 (which I recall fixing this problem in the past); however, it is now also not doing the trick.

I can import arcpy using the python interpreter in the command line:

and it is in the module list:

Thanks for any help!

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

at the bottom of your post and mine is a section called ... Related Content... go through those posts, since you are trying to use an unconventional installation.  Basically everything works well when ArcMap or ArcGIS Pro are allowed to install their version of python in their preferred location.  If you have previous versions already installed and want to keep them, then there are hoops you have to go through to ensure that when python is invoked through the little-used arcmap IDE that it points to the right location (which you can fix within arcmap).  The approach you want to take will depend on what works best for you given the information in all those links.

forestknutsen1
MVP Regular Contributor

Dan Patterson wrote:

since you are trying to use an unconventional installation. Basically everything works well when ArcMap or ArcGIS Pro are allowed to install their version of python in their preferred location.

Hmmm.... this (C:\Program Files (x86)\Python27\ArcGIS10.1) is not the normal location for 10.1? This is where it shows up on my machine I have not tried to modify the arc install of it or installed other versions of python. This is a clean new build. If this is not the normal location then perhaps I have a non-standard install of arc....

0 Kudos
DanPatterson_Retired
MVP Emeritus

This is just for python 2.7 for 10.3... was the same in 10.1  This is just reported through pyscripter... I don't know what pycharm does, but you should have a c:\python27 directory as below (just ignore the zip files... the c:\program files are for pyscripter

Python_path.png

This is what Pythonwin report which I also use (you can ignore the c:\\Program... it is for ArcGIS Pro.

>>> import sys

>>> sys.path

['', 'C:\\WINDOWS\\SYSTEM32\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\\lib', 'C:\\Python34\\Lib\\site-packages\\pythonwin', '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', 'C:\\Python34\\lib\\site-packages\\win32', 'C:\\Python34\\lib\\site-packages\\win32\\lib']

>>>

forestknutsen1
MVP Regular Contributor

Yep, it is just not in that location, but in program files. PyCharm is fine with the location. It is just when I go to seclude a task the windows system does not see the right install of python, so it fails on the import arcpy line. Anyway, I guess I will have to get on to our IT people who packaged Arc up for distribution within the organization and see if they changed the location...   Thanks for the input. I am still wondering why windows will not honor me setting the path, pythonhome, and pythonpath values in the system environment to the non standard location.

0 Kudos