Firebase import module fails with ModuleNotFoundError: No module named 'Crypto' - python

I am trying to launch a script I wrote that is supposed to read data from a firebase db but it throws the following error:
Traceback (most recent call last):
File "myScript.py", line 8, in <module>
from firebase import Firebase
File "/Users/georgeoprea/Library/Python/3.8/lib/python/site-packages/firebase/__init__.py", line 20, in <module>
from Crypto.PublicKey import RSA
ModuleNotFoundError: No module named 'Crypto'
I have tried to install Crypto in the following ways:
pip3 install Crypto
pip3 install pycryptodome
When I run pip3 show Crypto I get the following output:
Name: crypto
Version: 1.4.1
Summary: Simple symmetric GPG file encryption and decryption
Home-page: https://github.com/chrissimpkins/crypto
Author: Christopher Simpkins
Author-email: git.simpkins#gmail.com
License: MIT license
Location: /Users/georgeoprea/Library/Python/3.8/lib/python/site-packages
Requires: Naked, shellescape
Required-by:
This is the list of imports I have in myScript.py:
from bs4 import BeautifulSoup
import time
import smtplib
from datetime import datetime
import json
import random
from email.message import EmailMessage
from firebase import Firebase
OS info: macOS 12.1 running on M1 Pro.
What could I do to have my script recognise the Crypto module?

This might be somewhat related to this question.
/e:
Ok, since you are using this firebase package, I can hopefully help you out.
First of all, it's the package's fault that it isn't running. While it depends on many external packages, it has none of them defined.
This is what I had to do in a clean virtual environment just to be able to do from firebase import Firebase:
pip install sseclient python_jwt gcloud pycryptodome requests-toolbelt
Here is the requirements.txt I ended up with in the clean environment. Notice, that this was only for importing a single class from the package. There still might be other dependencies hidden somewhere, waiting to throw an exception.
I encourage you to give feedback to the developer about this issue. Even better, fix this yourself and open a Pull Request. You might help others with the same issue.

I found a workaround for this. I simply used another module to read from the firebase db. Instead of using firebase I used firebase_admin as mentioned in the firebase documentation. firebase_admin doesn't use Crypto so there's no more problem from this point of view. However I had to change a little bit how I retrieve and write data.

Related

Error with Python SDK for IBM Watson when importing into Pycharm

The error I receive is:
DeprecationWarning: watson-developer-cloud moved to ibm-watson. To get
updates, use the new package.
service = watson_developer_cloud.AssistantV1(
I have tried updating watson-developer-cloud using pip install however I still have the same error.
The code used is below. All done in Python. Just left out the API key from the original code.
Any help is appreciated.
service = watson_developer_cloud.AssistantV1(
iam_apikey= '',
version= '2021-01-20'
import os
from pathlib import Path
import slack
import ibm_watson
import ibm_cloud_sdk_core
import watson_developer_cloud
from ibm_watson import AssistantV1
from dotenv import load_dotenv
)
See here for the instructions on that Python package for IBM Watson services. It is like stated in the warning:
watson-developer-cloud is now named ibm-watson. What you have to do is
pip install ibm-watson
or
pip install --upgrade ibm-watson
Because the packagae is named ibm-watson, you would need to use that name for import...
import ibm-watson
or
from ibm_watson import AssistantV1
See the linked repository for examples.

Unable to import 'flask_uploads' pylint(import-error)

I installed flask-upload module in windows 10:
pip install flask flask-wtf flask-uploads
The results were:
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 WTForms-2.3.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 flask-uploads-0.2.1 flask-wtf-0.14.3 itsdangerous-1.1.0
Then in the text editor there is an error when I import the module as shown in the screenshot. unable to import flask-uploads
After running the app.py the following are the errors in cmd:
Error: While importing "app", an ImportError was raised:
Traceback (most recent call last):
File "c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "C:\Users\seanv\OneDrive\Documents\web dev\##pprojects\flask\flask_uploads\app.py", line 4, in <module>
from flask_uploads import configure_uploads, IMAGES, UploadSet
File "c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\flask_uploads.py", line 26, in <module>
from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug' (c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\werkzeug\__init__.py)
May someone who understands the problem help me with possible solutions or suggestions. Thank you in advance.
Your app is using Flask-Uploads.
Back in February 2020, there was an update for Werkzeug, a library which Flask and many libraries, including Flask-Uploads, is based on.
This update introduced a breaking change, as Werkzeug changed its API, ie. the import of secure_filename.
I provided a pull request to Flask-Uploads, which the maintainer accepted. But very sadly and unfortunately the maintainer did not want to provide a new package for PyPi.
So, while you could install the updated Flask-Uploads via a commit id from its GitHub repository, you cannot any longer install it from PyPi.
I asked the maintainer for a new release, I also offered my help, but no chance.
So, finally, I decided to fork the library.
Here is the new package on PyPi
https://pypi.org/project/Flask-Reuploaded/
Here is the repository
https://github.com/jugmac00/flask-reuploaded
It is a drop-in replacement. So you just have to install the new package and it just works. No need to change any imports or code in your application.

Unable to import database module from firebase_admin

I'm simply trying to add the Firebase Admin SDK to my Python script, but am unable to import the database module due to a TypeError in one of the library's python scripts.
I installed the library as instructed:
sudo pip install firebase-admin
I initialized the Firebase Admin SDK as instructed:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
But it breaks:
>>> import firebase_admin
>>> from firebase_admin import credentials
>>> from firebase_admin import db
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda/lib/python3.6/site-packages/firebase_admin/db.py", line 33, in <module>
from firebase_admin import _http_client
File "/anaconda/lib/python3.6/site-packages/firebase_admin/_http_client.py", line 30, in <module>
raise_on_status=False, backoff_factor=0.5)
TypeError: __init__() got an unexpected keyword argument 'status'
I peeked into the problematic script _http_client.py and saw that it imports requests, so I updated that with pip, to no avail.
No idea what could be the problem here. Any help would be much appreciated! Thank you!
Turns out, there was an old version of urllib3 lurking in my requests package. Removing the former from the latter did the trick. Thanks to shmee and Hiranya Jayathilaka for leading me to the solution!
Leaving an answer here to help people who are googling this find it easily.
Link to issue 262 on GitHub
You can check your version with:
import requests
from requests.packages import urllib3
print(urllib3.__version__)
>>>"1.16.1" # my output
You can check the location of the urllib3 you are using with:
import requests
from requests.packages import urllib3
print(urllib3.__file__)
>>>'...anaconda3/lib/python3.6/site-packages/requests/packages/urllib3/__init__.py'
If you are using Anaconda, you can physically remove the package, or you can just run conda update urllib3 in a terminal. That worked for me.
this worked for me , i just searched for the location of urllib3 package and then i deleted it .
you can find the location of the package by taping the following commands in python interpreter
from requests.packages import urllib3
print (urllib3.__file__)

No module named "requests" when trying to use google OAuth2 with Docker

I am trying to use google OAuth for my web app. To do so I installed the packages google-api-python-client and google-auth in my venv and during my Docker build(from a requirements.txt). Despite this when I run my app it can't find the requests module, complaining that:
flask.cli.NoAppException: While importing "debateit", an ImportError was raised:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/google/auth/transport/requests.py", line 23, in <module>
import requests
ImportError: No module named 'requests'
The import is as follows:
from google.auth.transport import requests
and is used like:
idinfo = id_token.verify_oauth2_token(token, requests.Request(), app.config["GOOGLE_LOGIN_CLIENT_ID"])
Other imports such as the id_token.verify_oauth2_token work fine.
I checked my docker build and it says I have included google-auth correctly:
Installing collected packages: ... google-auth, httplib2, google-auth-httplib2, google-api-python-client
Successfully installed ... google-api-python-client-1.7.3 google-auth-1.5.0 google-auth-httplib2-0.0.3 httplib2-0.11.3 ...
I can clearly see the google.auth.transport.requests module when I look in the venv, it just doesn't work in the app itself.
What am I missing? What could cause this module to not be found?
So I found out what was wrong - within the google.auth.transport.requests module they try to import the library "requests". I did not have this library installed. I have done so and it works now.
The guide I was following: https://developers.google.com/identity/sign-in/web/backend-auth did not mention that you need to install this library. I misunderstood what the import for requests in the requests module was supposed to do.
As reported in the documentation, it should be more likely like:
import google.auth.transport.requests
import requests
request = google.auth.transport.requests.Request()
credentials.refresh(request)
But for your purpose I'll suggest:
from google.auth.transport.requests import Request
then change the following from:
idinfo = id_token.verify_oauth2_token(token, requests.Request(), app.config["GOOGLE_LOGIN_CLIENT_ID"])
to:
idinfo = id_token.verify_oauth2_token(token, Request(), app.config["GOOGLE_LOGIN_CLIENT_ID"])
It was an error because inside the path google.auth.transport.requests there is no function or class which is named requests.
My suggestion is based on the line
idinfo = id_token.verify_oauth2_token(token, requests.Request(), app.config["GOOGLE_LOGIN_CLIENT_ID"])
which show us that you use a class named Requests() which is present into google.auth.transport.requests as you can see in the documentation.
I know this was answered but you can quickly install those libraries globally by the running the command :
pip install google-auth
Here is how to install pip or installing the libraries in local virtual environment if someone doesn't want to install them globally:
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
pip install requests
It seems like google.auth.transport.requests uses requests.

python freeopcua import error: cannot import name Client

folks, i got python 3.5.0 installed on a windows 7 machine and used pip3 to install dependencies cryptography, dateutil, lxml and pytz as mentioned on the freeopcua homepage.
thereafter I installed freeopcua using pip3 as well.
when trying to run one of the examples https://github.com/FreeOpcUa/python-opcua/blob/master/examples/client_to_kepware.py I got the error
1 import sys
2 sys.path.insert(0, "..")
3 import logging
4
5 from opcua import Client
6 from opcua import uaprotocol as ua
"Traceback (most recent call last):
File "xxx\Desktop\opcua.py", line 5, in
from opcua import Client
File "xxx\Desktop\opcua.py", line 5, in
from opcua import Client
ImportError: cannot import name 'Client'"
in my directory "xxx\Python35-32\Lib\site-packages" I do see opcua and freeopcua-0.09.3-py3.5.egg-info so it appears to be intalled correctly.
inside opcua package there is a __init__ importing
from opcua.client.client import Client from a folder client that exists on the same level as __init__. that folder has a module client.py and that module is holding class "Client". so to me everything appears fine but I am not very experienced here.
Not sure what is causing this? thanks for help!
above issue did take me quite some time and after being stuck for one evening I decided to ask. However, I eductated myself on packages that morning and appears like sys.path(0..) is the reason. Not 100% sure why it is used but it somehow changes directory. After puting file into my Python directory /Pyton35-32 it is working

Categories

Resources