cant import flask-wtf after install - flask

I have been looking around for an answer to this question, but everywhere I see the advice of running a pip install flask-wtf in the virtual environment. The requirements have already been satisfied in mine, but for some reason I am getting a missing module error. I am working on a school project building a website using flask and would really appreciate the help. My import is:
from flask_wtf import Form`
When I try to run the install command I get a message that says the requirement is already satisfied, as shown in this image.

Based on the screenshot, your flask-wtf and friends are installed outside virtualenvs, in the system site-packages directory.
It'd be a good idea to uninstall those from the global site-packages directory (python3 -m pip uninstall flask-wtf wtforms flask jinja2 click werkzeug markupsafe itsdangerous), create and activate a virtualenv (python3 -m venv my_venv and ./my_venv/bin/activate), then reinstall the dependencies within the virtualenv.

Related

ModuleNotFoundError: No module named 'flask_openid' (for Python3.6)

I was trying to run a Flask project using Python 3.6.
I encountered an error:
...
from flask_openid import OpenID
ModuleNotFoundError: No module named 'flask_openid'
Flask-OpenID is available in my Python v3.5 dist-packages.
(When I run:
"sudo pip3 install Flask-OpenID", it shows
"Requirement already satisfied (use --upgrade to upgrade): Flask-OpenID in /usr/local/lib/python3.5/dist-packages" )
What should I do to install openid for Python 3.6?
The documentation states that you should import OpenID as follows:
from flask.ext.openid import OpenID
The package itself is installed correctly (in your Python3.5 environment), as shown by pip when you try to install it again:
Requirement already satisfied (use --upgrade to upgrade): Flask-OpenID in /usr/local/lib/python3.5/dist-packages
However, as you state the in your question:
I was trying to run a Flask project using Python 3.6
You might want to make sure your python3 and pip3 are actually pointing to where you want them to, e.g. on your terminal:
$ ls -l $(which pip3)
Or even better, you should really look into creating virtualenvs for your projects, it helps a lot avoiding these kinds of problems in the first place:
create a new Python 3.6 virtualenv
activate your new virtualenv
install your requirements with pip inside the virtualenv
Then run your script in this virtualenv, and you'll be sure you are using exactly the Python you want, and your dependencies are where you expect them to be (and only there, not somewhere else messing up other projects).
Now this might look like a lot of effort, but it takes no more than a couple minutes the first time you do it, will quickly become second nature, and save you a ton of headache down the road.
For me,
python3.6 -m pip install flask_openid
solved the issue.
The above command will install openid for python3.6.

No module named 'chartit';

I am trying to use chartit in django and in its documentation it says add chartit to INSTALLED APPS in "settings.py".
When I try to do that, it gives this error:
ImportError: No module named 'chartit'
How do I import it?
Thank you.
PS-Sorry, it's a silly question.
You missed installing it with pip install django_chartit.
EDIT:
The error you described is thrown by python if a module is not found in the running environment. You need to make sure, that you've installed it in the environment that is used by your django.
Try typing pip list in the shell you usually use to kick your django with python manage.py runserver to figure out what is installed there.
If your django lives inside of a IDE like PyCharm - you need to check the project settings there for the environment used to launch django.
As you don't use virtualenv (which is highly recommended) you install your modules system wide. If you are on linux there might be python3 and python (which is python 2). If your pip belongs to python2 and you have installed django in python3 or vice versa this might be the issue.
from chartit import DataPool, Chart

Path issue Pip (Psycopg2) inside VirtualEnv

When using Pip (6.0.8) to install Django (1.9) and Psycopg2 (2.6.1), Django got installed in the env/lib/python2.7/site-packages folder and Psycopg2 in the env/lib64/python2.7/site-packages folder.
When I'm using command line (eg python manage.py migrate) or >>> import psycopg2, this all works fine. But when Mod_WSGI is running the application it complains that there is no module Psycopg2.
I'm able to work around this issue by adding the lib64 as a python path in my Apache conf file, but I'm pretty sure this is not the best possible way.
Any suggestions for a better solution?
Btw: I noticed by the way that Pip 7.1.2 is installing Django in Lib64 as well iso Lib.
Yes, there is with the use of --install-option. Have a look at the docs

ImportError: No module named flask_mail

from flask_mail import Mail,Message
from flask import Flask
I am trying to mail but import error is occurring
The are two packages by that name:
The project found on GitHub and in PyPI uses flask_mail as the package name; see their documentation and project source code.
Their layout indeed requires:
from flask_mail import Mail, Message
This is a fork of the other project, but is currently actively maintained.
There is a project on Bitbucket, and their Flask-Mail documentation and the project source code show that the correct import is:
from flaskext.mail import Mail, Message
This project appears to be outdated and has not seen an update for almost 3 years now. The Github project names the same original author, it appears to be an updated fork. I'd stick with the Github project.
If neither works, then there is no such module installed, not in the location that the Python version running your Flask server can find.
You have to install flask_mail in order to be able to import it.
if you are working with linux type this into your terminal and hit enter:
$ sudo pip install flask_mail
Here is a simple way to save time. Upgrade or update your pip before installing Flask-Mail. It worked on my Mac
pip install --user --upgrade pip
pip install Flask-Mail

Running Django in Virtualenv on EC2 -- ImportError: No module named django.core.management

I developed a django application locally, in a git repo. I launched an EC2 instance for the project and I set up a virtualenv with (what I believe to be) the correct packages/dependencies. I then proceeded to clone my repo into the virtualenv. Right now, I'm having difficulty as I'm receiving the following errors:
I attempted to use python manage.py runserver example.com/8080 to test. I was sure to activate the virtualenv using source bin/activate, just like I did in my local virtualenv. When I call ... runserver I get the following error:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Here is what sudo pip freeze produces:
Warning: cannot find svn location for distribute==0.6.24dev-r0
Cheetah==2.4.4
Django==1.5.2
Fabric==1.8.0
GnuPGInterface==0.3.2
Landscape-Client==12.05
M2Crypto==0.21.1
PAM==0.4.2
PyYAML==3.10
South==0.8.2
Twisted-Core==11.1.0
Twisted-Names==11.1.0
Twisted-Web==11.1.0
apt-xapian-index==0.44
argparse==1.2.1
boto==2.2.2
chardet==2.0.1
cloud-init==0.6.3
command-not-found==0.2.44
configobj==4.7.2
## FIXME: could not find svn URL in dependency_links for this package:
distribute==0.6.24dev-r0
django-s3-folder-storage==0.1
django-storages==1.1.8
django-tastypie==0.10.0
ecdsa==0.9
euca2ools==2.0.0
gunicorn==18.0
httplib2==0.7.2
keyring==0.9.2
language-selector==0.1
launchpadlib==1.9.12
lazr.restfulclient==0.12.0
lazr.uri==1.0.3
medusa==0.5.4
meld3==0.6.5
oauth==1.0.1
paramiko==1.12.0
psycopg2==2.5.1
pyOpenSSL==0.12
pycrypto==2.4.1
pycurl==7.19.0
pyserial==2.5
python-apt==0.8.3ubuntu7.1
python-dateutil==2.1
python-debian==0.1.21ubuntu1
simplejson==2.3.2
six==1.4.1
supervisor==3.0a8
ufw==0.31.1-1
unattended-upgrades==0.1
virtualenv==1.10.1
wadllib==1.3.0
wsgiref==0.1.2
zope.interface==3.6.1
...and this is my ./manage.py file:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Any thoughts on how I can fix this error? I tried to change #!/usr/bin/env python to #!/var/www/paletto-env/bin python, trying to direct it to my actual python path, but it did not lend to any apparent change, so I changed it back.
Thanks for the help.
Looks like you're environment can't find Django, even though it's clearly in your pip freeze.
Try opening a Python (not Django) shell from your virtual environment and entering:
import django
django.VERSION
If you run into the same error, there's probably an issue with your Django install. Your virtual environment probably can't find it. You could try modifying the path settings, or just reinstall Django.
If you can successfully import Django, or if you tried reinstalling and it doesn't work, you may have a permission problem. Ensure that the user responsible for running the server has access to wherever your python libraries are stored from the virtualenv.
I had pretty much the exact same problem as you and this is how I solved it (Disclaimer: I'm not sure if this is the absolute correct way but it worked for me and everything seems correct).
Short Answer:
Try pip install (package) instead of sudo pip install (package)
Long Answer:
I gave the Django complete install doc (See here) a quick read through and came across a bit that basically said you dont need super user privileges when using pip in the virtualenv. I just assumed that either would be fine but I now realize that's probably not the case.
I suspect that because I entered sudo pip install django it installed it somewhere above my local bin in my virtualenv for the project. I suspect this because when I enter python manage.py runserver I get an error; however, when I enter sudo python manage.py runserver everything functions properly.
Also, typing sudo pip freeze reveals my larger library whereas pip freeze reveals my local library for my virtualenv.
I didn't want to type sudo (do stuff) before everything and I wanted a nice, clean and proper virtualenv so I just reinstalled django but to my local virtual env with pip install django and now django is in the proper virtualenv library, pip freeze returns the proper contents, and python manage.py runserver functions properly!
django-admin.py startproject by default creates the shebang in manage.py with #!/usr/bin/env python.
If this is not the path to your python executable, or if you use python3, just edit the manage.py to reflect this.
Reinstall all python packages angain after you have activated your virtualenv.
Maybe the Django has lost some plugin with pip, so we can install Django with Tarball:
Go https://www.djangoproject.com/download/1.6.5/tarball/
Download Django-*.tar.gz
install it.
$ tar zxvf Django-1.6.5.tar.gz
$ cd Django-1.6.5/
$ python setup.py install
more ... (https://stackoverflow.com/a/24323774/686105