alexfriant

Do not name your Python script "pytest.py" with ArcGIS Pro installed

Discussion created by alexfriant on Feb 6, 2018
Latest reply on Feb 6, 2018 by alexfriant

Cut to the chase:

If you attempt to import the arcgis module (or even parts of it) in your python script, then do not name your python script "pytest.py". You will see some very strange behavior and your script will fail. The name of your script will conflict with pandas initialization scripts, which just-so-happen to have a variable named "pytest".

 

The Long Version (skip if you are squeamish):

I have ArcGIS Pro 2.1 with the patch installed. I was troubleshooting a script and decided to create a simple python test script to figure out what was going on. I innocently named it "pytest.py". I suddenly started seeing strange errors I hadn't previously seen when attempting to execute my script. Okay, fine, I thought. Let me see if I can manually run these commands "import arcgis" in the Python Shell. What happened next made no sense at all - the Python Shell responds by re-running my "pytest.py" script and the same errors occurred! What? I was in a completely different session.

 

So I uninstalled ArcGIS Pro, deleted the Python folder and reinstalled ArcGIS Pro. I opened the Python Shell and manually entered the command "import arcgis". Again, it responded by re-running my "pytest.py" script and errored out. This fried my brain. The day ended and I went home.

 

After a long night of nightmares of Python acting weird, I came to work this morning and carefully examined the Traceback results. I saw that the Pandas package was reporting "AttributeError: module 'pytest' has no attribute 'mark'". It suddenly clicked: I decided to rename my script "mytest.py" and everything worked fine and the manual command errors also disappeared. It turns out that the name of your script will conflict with pandas initialization scripts, which is part of arcgis intialization, which just-so-happen have a variable named "pytest".

 

I just thought I'd put this out there for the next poor soul who attempts to name a python test script "pytest.py" and import arcgis inside of it. And yes, I learned to pay more attention to traceback results ;-)

Outcomes