I get the following error when I try to import passlib.
ImportError: No module named passlib.apps
I have tried to install it via the following commands to install it and they claim it is sucess or it is already there yet my program still refuses to import it:
pip install passlib
sudo pip install passlib
apt-get install python-pip pip install passlib
Here is how I construct my environment:
I navigate to Documents/45
I run command: source env/bin/activate
I then run pip install passlib and it tells me:
Requirement already satisfied: passlib in ./env/lib/python2.7/site-packages
I then type ./run.py
(env) jsnyder10@jsnyder10-VirtualBox:~/Documents/45$ ./run.py
Traceback (most recent call last):
File "./run.py", line 2, in <module>
from app import app
File "/home/jsnyder10/Documents/45/app/__init__.py", line 70, in <module>
from app import views, models
File "/home/jsnyder10/Documents/45/app/views.py", line 9, in <module>
from .forms import EditForm, PostForm, SearchForm, RegistrationForm, LoginForm
File "/home/jsnyder10/Documents/45/app/forms.py", line 5, in <module>
from .models import User
File "/home/jsnyder10/Documents/45/app/models.py", line 6, in <module>
from passlib.apps import custom_app_context as pwd_context
ImportError: No module named passlib.apps
(env) jsnyder10@jsnyder10-VirtualBox:~/Documents/45$ pip install passlib
Requirement already satisfied: passlib in ./env/lib/python2.7/site-packages
Here is my code run.py
#!flask/bin/python
from app import app
app.run(debug=True)
Here is init.py
init__.py
import os
from flask import Flask
from flask.json import JSONEncoder
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_mail import Mail
from flask_babel import Babel, lazy_gettext
from config import basedir, ADMINS, MAIL_SERVER, MAIL_PORT, MAIL_USERNAME, \
MAIL_PASSWORD
from .momentjs import momentjs
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
lm.login_message = lazy_gettext('Please log in to access this page.')
mail = Mail(app)
babel = Babel(app)
class CustomJSONEncoder(JSONEncoder):
"""This class adds support for lazy translation texts to Flask's
JSON encoder. This is necessary when flashing translated texts."""
def default(self, obj):
from speaklater import is_lazy_string
if is_lazy_string(obj):
try:
return unicode(obj) # python 2
except NameError:
return str(obj) # python 3
return super(CustomJSONEncoder, self).default(obj)
app.json_encoder = CustomJSONEncoder
if not app.debug and MAIL_SERVER != '':
import logging
from logging.handlers import SMTPHandler
credentials = None
if MAIL_USERNAME or MAIL_PASSWORD:
credentials = (MAIL_USERNAME, MAIL_PASSWORD)
mail_handler = SMTPHandler((MAIL_SERVER, MAIL_PORT),
'no-reply@' + MAIL_SERVER, ADMINS,
'microblog failure', credentials)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
if not app.debug and os.environ.get('HEROKU') is None:
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('tmp/microblog.log', 'a',
1 * 1024 * 1024, 10)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('microblog startup')
if os.environ.get('HEROKU') is not None:
import logging
stream_handler = logging.StreamHandler()
app.logger.addHandler(stream_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('microblog startup')
app.jinja_env.globals['momentjs'] = momentjs
from app import views, models
models.py
from hashlib import md5
import re
from app import db
from app import app
from config import WHOOSH_ENABLED
from passlib.apps import custom_app_context as pwd_context
pip list and freeze outputs, both show passlib 1.7.1
(env) jsnyder10@jsnyder10-VirtualBox:~/Documents/45$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
appdirs (1.4.3)
packaging (16.8)
passlib (1.7.1)
pip (9.0.1)
pyparsing (2.2.0)
setuptools (35.0.2)
six (1.10.0)
wheel (0.29.0)
(env) jsnyder10@jsnyder10-VirtualBox:~/Documents/45$ pip freeze
appdirs==1.4.3
packaging==16.8
passlib==1.7.1
pyparsing==2.2.0
six==1.10.0
It worked for me, though, so the problem is probably in your environment.
-I am using Python 2.7 and installed (via pip) passlib-1.7.1.-
I didn't realize I was runnining the environment from flask/bin so running the following command fixed it
flask/bin/pip install passlib