Home > Back-end >  ImportError: cannot import name 'tasks_v2' from 'google.cloud' (unknown location
ImportError: cannot import name 'tasks_v2' from 'google.cloud' (unknown location

Time:02-12

I'm trying to incorporate google-cloud-tasks Python client within my fastapi app. But it's giving me an import error like this:

from google.cloud import tasks_v2
ImportError: cannot import name 'tasks_v2' from 'google.cloud' (unknown location)

packages in my project, pip freeze:

aiohttp==3.8.1
aiosignal==1.2.0
async-timeout==4.0.2
attrs==21.4.0
boto3==1.20.51
botocore==1.23.51
CacheControl==0.12.10
cachetools==4.2.4
certifi==2021.10.8
charset-normalizer==2.0.11
click==7.1.2
confuse==1.4.0
firebase-admin==5.0.1
Flask==1.1.4
frozenlist==1.3.0
google-api-core==1.31.5
google-api-python-client==2.36.0
google-auth==1.35.0
google-auth-httplib2==0.1.0
google-cloud==0.34.0
google-cloud-core==2.2.2
google-cloud-firestore==2.3.4
google-cloud-storage==2.1.0
google-cloud-tasks==2.7.2
google-crc32c==1.3.0
google-resumable-media==2.2.0
googleapis-common-protos==1.54.0
greenlet==1.1.2
grpc-google-iam-v1==0.12.3
grpcio==1.43.0
grpcio-status==1.43.0
httplib2==0.20.4
idna==3.3
itsdangerous==1.1.0
Jinja2==2.11.3
jmespath==0.10.0
MarkupSafe==1.1.1
msgpack==1.0.3
multidict==6.0.2
numpy==1.22.2
packaging==21.3
pandas==1.3.2
proto-plus==1.20.0
protobuf==3.19.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycryptodome==3.14.1
pyee==7.0.4
PyMySQL==1.0.2
pyparsing==3.0.7
python-dateutil==2.8.2
python-dotenv==0.19.1
pytz==2021.3
PyYAML==6.0
requests==2.27.1
rsa==4.8
s3transfer==0.5.1
schedule==1.1.0
six==1.16.0
slackclient==2.9.3
slackeventsapi==2.2.1
SQLAlchemy==1.4.22
uritemplate==4.1.1
urllib3==1.26.8
Werkzeug==1.0.1
yarl==1.7.2

Python version I'm using for this virtualenv is Python 3.8.9

OS: macOS Monterey 12.1

Tried this solution here, but it didn't work. :(

CodePudding user response:

After doing some more research online I realized that installation of some packages is missed due to some existing packages. This issue helped me realize I need to reorder the position of google-cloud-tasks in my requirements.txt. So what I did was pretty simple, created a new virtualenv installed google-cloud-tasks as my first package and then installed everything else and finally the problem is solved.

Long story short the issue is the order in which packages are installed and that's why some packages are getting missed.

  • Related