Django-registration ImportError: No module named signals - django-registration

I am trying to write a signal listener for django-registration and I am getting the import error: no module named signals. But I could import registration.
Here is my code
from django.contrib.auth import login
from registration.signals import user_registered
def user_registered_handler(sender, **kwargs):
"""signal intercept for user_login"""
user = kwargs['user']
user.is_active = True
user.save()
login(user)
user_registered.connect(user_registered_handler)
-- Thanks in advance.

Try using a specific path to version 0.8. I noticed that using easy install and pip installed 0.7 which does not have signals.py.
Using pip:
$ pip install -Iv https://bitbucket.org/ubernostrum/django-registration/downloads/django-registration-0.8-alpha-1.tar.gz

Related

ModuleNotFoundError: No module named 'flask_wtf' ... verified installed in virtualenv

My import statements are as follows:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired
I am able to execute the file - blank.py - within Pycharm and do not receive a ModuleNotFoundError.
Whenever I execute flask run in terminal I get ModuleNotFoundError: 'flask_wtf' and it traces back to 'blank.py'.
I am not sure why this is happening as I have both flask and flask-wtf installed globally and locally. I have never had this problem when working with other libraries.
How do I fix this? Thank you for you help.

ImportError while running "Flask run app.py" but if I run "python3 app.py" then there is no import error and works fine

from flask import Flask, jsonify, request
from flask_restful import Api, Resource
from transformers import pipeline
#import transformers
app = Flask(__name__)
api = Api(app)
summarizer = pipeline("summarization", model='facebook/bart-large-cnn' )#t5-large
print("summarizer loaded")
class Summary(Resource):
def post(self):
# write what to do for post request and Add class
#Load the data
postedData = request.get_json()
#Validate the data
news = postedData['news']
summary_extractive = summarizer(news,min_length=90, max_length = 120)
#make json and return
retJSON = {
'Message': summary_extractive[0]['summary_text'],
'word_count': len(summary_extractive[0]['summary_text'].split()),
'Status Code': 200,
}
return jsonify(retJSON)
api.add_resource(Summary, '/get_summary')
if __name__ == '__main__':
app.run(debug=True)#host='0.0.0.0'
Error while running with flask run:
from transformers import pipeline
ImportError: cannot import name 'pipeline' from 'transformers' (unknown location)
But if I run with python3 app.py then there is no error.
I'm working in venv enviroment on macOS.
In pip list I'm able find the missing module transformer.
I have faced similar issue which is causes due to old version of pip. Follow the below step to resolved the issue:
upgrade your pip version use this command pip install --upgrade pip
Uninstall old version of transformer pip uninstall transformers
install again pip install transformers
It works have a nice day

"How to fix' ImportError: cannot import name 'SQLAlchemy'

import os
from flask import Flask
from flask_wtf import FlaskForm
import sqlalchemy
from flask_sqlalchemy import SQLAlchemy
bsdir = os.path.abspath(os.path.dirname(__file__))
# print(bsdir)
app = Flask(__name__, template_folder = 'template')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+os.path.join(bsdir,'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATION'] = False
db = SQLAlchemy(app)
class Puppy(db.Model):
pass
Traceback (most recent call last):
File "D:\PYTHON\GIT_EXC\FLASK_\flask_sqlalchemyex.py", line 5, in
from flask_sqlalchemy import SQLAlchemy File "D:\PYTHON\GIT_EXC\FLASK_\flask_sqlalchemy.py", line 4, in
from flask_sqlalchemy import SQLAlchemy ImportError: cannot import name 'SQLAlch
Try using this command
pip install flask-sqlalchemy --user
It worked for me
And If you are using PyCharm go to file
Select Invalidate caches and restart
Try to install it with these commands , (it worked for me):
pip install flask-sqlalchemy
pip3 install flask-sqlalchemy
Refer this site for Example
or
Refer the official guide site for installation
if it doesnt worked then try above commands with --user at the end of both commands
another solution maybe to install an IDE (if you are not using one) like PyCharm ; rather than a some simple text editors
First command installs package to python v2.x
Second one installs package to python 3.x
If you want to use 3.x to run your app ;then go to configuration and change it to python 3.x
Refer this for Getting Help / Development / Bug reporting
Try changing the name of your .py file. It may be causing a conflict with the flask-sqlalchemy package.
"D:\PYTHON\GIT_EXC\FLASK_\flask_sqlalchemy.py"
I faced same issue while instantiating airflow db by command
$airflow db init
error: ImportError: cannot import name 'SQLAlchemyAutoSchema'
Fixes:
Uninstall:
$pip uninstall marshmallow-sqlalchemy
Then upgrade it to version 0.24.0
$pip3 install marshmallow-sqlalchemy==0.24.0
My problem resolved and able to initialize airflow db.

Tensorflow Hub and CGI

I have installed tensorflow_hub package in python 3.6. The package can be imported correctly when I test it in python console. However, when I use it in a cgi-script an error occurs:
no module named tensorflow_hub
Source Code
#!/usr/bin/python3.6
import sys
import cgitb
import cgi
t = ''
try:
import tensorflow_hub as tf
except Exception as e:
t = str(e)
cgitb.enable()
sys.stdout.write("Content-Type: application/json")
sys.stdout.write("\n")
sys.stdout.write("\n")
result = dict()
result['data'] = t
sys.stdout.write(json.dumps(result,indent=1))
sys.stdout.write("\n")
Could you explain me which is the problem? I tested other packages (e.g. tensorflow) but I hadn't any issue.
Edit
To install the package:
pip3 install tensorflow-hub
which pip3
/usr/bin/pip3
To answer my question giving feedback to others with similar problem:
The tensorflow_hub was in the ~/.local/lib/python3.6/site-packages/ where the cgi hasn't got access.
To find the location:
pip3 show tensorflow_hub
I observed that all the other packages where in /usr/local/lib/python3.6/dist-packages/
So, I moved the package from the first location to the second.
This helped me:
Why can't python find some modules when I'm running CGI scripts from the web?

Python 3: No module named zlib?

I am trying to run my Flask application with an Apache server using mod_wsgi, and it has been a bumpy road, to say the least.
It has been suggested that I should try to run my app's .wsgi file using Python to make sure it is working.
This is the contents of the file:
#!/usr/bin/python
activate_this = '/var/www/Giveaway/Giveaway/venv/bin/activate_this.py'
with open(activate_this) as f:
code = compile(f.read(), "somefile.py", 'exec')
exec(code)
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/Giveaways/")
from Giveaways import application
application.secret_key = 'Add your secret key'
However, when I run it, I get this error:
ImportError: No module named 'zlib'
And no, I am not using some homebrewed version of Python - I installed Python 3 via apt-get.
Thanks for any help.
does the contents of somefile.py include the gzip package? in which case you may have to install gzip package via pip or similar

Resources