Strange and horrifying Python error story

Note) It is a story for beginners to be careful about the import specifications.

I was testing a certain feature in Python.

The following sample code, which was working yesterday, suddenly started giving an error. The environment is pyenv + pipenv + python3.7 + Google Cloud SDK (This is the code to write to Google Firestore)

insert.py


from google.cloud import firestore

db = firestore.Client()
db.collection(u'users').document().set({
    u'first': u'oda',
    u'last': u'nobunaga',
    u'born': 1534
})

The content of the error is as follows

>> pipenv run insert
Loading .env environment variables...
Traceback (most recent call last):
  File "insert.py", line 1, in <module>
    from google.cloud import firestore
  File "/mnt/v01/workspace/sandbox-python-firestore/.venv/lib/python3.7/site-packages/google/cloud/firestore.py", line 18, in <module>
    from google.cloud.firestore_v1 import __version__
  File "/mnt/v01/workspace/sandbox-python-firestore/.venv/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 17, in <module>
    from pkg_resources import get_distribution
  File "/mnt/v01/workspace/sandbox-python-firestore/.venv/lib/python3.7/site-packages/pkg_resources/__init__.py", line 33, in <module>
    import platform
  File "/home/dev-user/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/platform.py", line 116, in <module>
    import sys, os, re, subprocess
  File "/home/dev-user/.pyenv/versions/anaconda3-5.3.1/lib/python3.7/subprocess.py", line 140, in <module>
    import select
  File "/mnt/v01/workspace/sandbox-python-firestore/select.py", line 3, in <module>
    db = firestore.Client()
AttributeError: module 'google.cloud.firestore' has no attribute 'Client'

I think people who love Python on a regular basis feel a little bit, but I have a bad feeling because it is an import error in the situation where pyenv and pipenv are used at the same time.

But yesterday it was working fine. I'm also worried about gcloud auth.

Here, I notice something strange.

  File "/mnt/v01/workspace/sandbox-python-firestore/select.py", line 3, in <module>
    db = firestore.Client()

why,

There is ./select.py that you shouldn't call. Certainly, I created select.py in ./ as a sample code earlier.

After removing this ./select.py, the program works fine.

After all

It seems that select.py in the current directory has been called from subprocess.py that was used during processing.

This time it was good because it was a sample program that I was writing by myself, but I wondered if it was necessary to pay attention to the file name especially when developing a team with Python, and it was an error that a cold thing ran on my spine.

Recommended Posts

Strange and horrifying Python error story
The story of Python and the story of NaN
A story about Python pop and append
Python Error Handling
A story about modifying Python and adding functions
[python] Compress and decompress
Python and numpy tips
[Python] pip and wheel
The story of Python without increment and decrement operators.
Batch design and python
Python iterators and generators
Python Not Implemented Error
Today's python error: killed
Python packages and modules
Vue-Cli and Python integration
[Python] Type Error: Summary of error causes and remedies for'None Type'
python small story collection
pytube execution and error
Golang error and panic
python input and output
Python and Ruby split
Python3, venv and Ansible
Python asyncio and ContextVar
[Python] for statement error
I got an error in vim and zsh in Python 3.7 series
Programming with Python and Tkinter
Python: Class and instance variables
Python 2 series and 3 series (Anaconda edition)
Python and hardware-Using RS232C with Python-
Python indentation and string format
Python real division (/) and integer division (//)
Install Python and Flask (Windows 10)
Story when iterating python tuple
About python objects and classes
About Python variables and objects
Apache mod_auth_tkt and Python AuthTkt
Å (Ongustromu) and NFC @ Python
Understand Python packages and modules
# 2 [python3] Separation and comment out
Python shallow copy and deep copy
Python and ruby slice memo
Python installation and basic grammar
I compared Java and Python!
[Python] SQLAlchemy error avoidance memorandum
Stumble story with Python array
About Python, len () and randint ()
About Python datetime and timezone
Python environment construction and TensorFlow
Python class variables and instance variables
[Python] Python and security-① What is Python?
python metaclass and sqlalchemy declareative
Error when playing with python
#python Python Japanese syntax error avoidance
Fibonacci and prime implementations (python)
Python basics: conditions and iterations
GAE + python + Django addictive story
Python bitwise operator and OR
Python debug and test module
Python list and tuples and commas
Python variables and object IDs
Python list comprehensions and generators