env() reference

5162
30
02-05-2020 10:13 AM
by Anonymous User
Not applicable

Hi, I'm trying to use Pycharm, as IDE for python, but it seemd that the function arcpy.env is missing from __init_.PY...

I'm using C:\Python27\ArcGISx6410.5 interpreter.

When I try to run it inside PyCharm I get :

C:\Python27\ArcGISx6410.5\python.exe U:/Prog/PYScript/Geosoft2ArcGIS.py
Traceback (most recent call last):
File "U:/Prog/PYScript/Geosoft2ArcGIS.py", line 12, in <module>
import arcpy
File "c:\arcgis\desktop10.7\ArcPy\arcpy\__init__.py", line 22, in <module>
from arcpy.geoprocessing import gp
ImportError: cannot import name gp

0 Kudos
30 Replies
by Anonymous User
Not applicable

You have to point pycharm to use the pythonw.exe (or python.exe) that is in the same path as arcpy. "c:\arcgis\desktop10.7\ArcPy\....

I've pointed Pycharm to C:\Python27\ArcGIS10.7, but arcpy is somewhere else, in the ArcGIS folder, C:\ArcGIS\Desktop10.7\arcpy, 

They are in seperate folders. no Python.exe in Arcpy folder (clean install)

0 Kudos
DanPatterson_Retired
MVP Emeritus

sorry, not an arcmap user... conda and Pro and Spyder

But

Importing ArcPy—Help | ArcGIS Desktop 

gives a protracted discussion of sys paths and paths and imports.  In essence, you IDE has to make sure it can find arcpy especially if it was installed before arcmap.

Perhaps one of the lurking pycharm ers or pyscripter s will leap in to the rescue to sort out your dilema

Joshua Bixby‌ ? Joe Borgione‌ ? Matthew Driscoll‌ ? amongst the arcmap users viewing this thread.  Any ideas? (besides switching to ArcGIS Pro)

0 Kudos
by Anonymous User
Not applicable

Thanks for your help.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Yves Allaire‌, let's cut out the script itself and try just running the import codes from within the Python console in PyCharm, just make sure the console interpreter is set to the same one you want to test.

PyDev console: starting.
Python 2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:30:55) [MSC v.1500 32 bit (Intel)] on win32
>>> from arcpy.geoprocessing import gp
>>> 
0 Kudos
by Anonymous User
Not applicable

Hi Joshua,

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Your screenshot shows you running the script.  I am asking you to open a clean Python console and try importing the arcpy module.

0 Kudos
by Anonymous User
Not applicable

When I create a new project from scratch and go to the Python console here is what I get:

import arcpy

C:\Python27\ArcGIS10.7\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py" --mode=client --port=61237
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['U:\\Prog\\PYScript\\untitled', 'U:/Prog/PYScript/untitled'])
PyDev console: starting.
Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:30:55) [MSC v.1500 32 bit (Intel)] on win32
import arcpy
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\ArcGIS\Desktop10.7\ArcPy\arcpy\__init__.py", line 22, in <module>
from arcpy.geoprocessing import gp
ImportError: cannot import name gp

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Are you able to import any packages for that Python bundle, e.g., numpy, xlrd, etc...

0 Kudos
by Anonymous User
Not applicable

I was able to import (install) them

0 Kudos
DanPatterson_Retired
MVP Emeritus

Joe means import from the command line in the python IDE, not install them.  The packages may indeed be installed but in a different "Site Packages"

0 Kudos