Note) It is a story for beginners to be careful about the import specifications.
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.
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.
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