Select to view content in your preferred language

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

1339
5
02-06-2018 10:21 AM
alex_friant
Occasional Contributor III

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 😉

5 Replies
DanPatterson_Retired
MVP Emeritus

  Not to mention potential copyright infringement on the name

alex_friant
Occasional Contributor III

Ha ha, yes, I did find that once I did some googling!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

alexfriant‌, I converting this thread to a discussion since you are mainly sharing and not asking a question or for help.

0 Kudos
alex_friant
Occasional Contributor III

Oops! Thanks, my bad.

0 Kudos
JoeBorgione
MVP Emeritus

Thanks for the heads up-  I've distributed this url to our user community.

That should just about do it....