Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'message_from_file' #13

Closed
giovannicimolin opened this issue Oct 18, 2018 · 12 comments
Closed

cannot import name 'message_from_file' #13

giovannicimolin opened this issue Oct 18, 2018 · 12 comments
Assignees
Labels

Comments

@giovannicimolin
Copy link

giovannicimolin commented Oct 18, 2018

When I try adding 'django_rest_passwordreset' to django apps, I get this error:

Traceback (most recent call last):
  File "manage.py", line 28, in <module>
    from django.core.management import execute_from_command_line
  File "/home/giovanni/git/ozzy-backend/venv/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
    from django.utils.version import get_version
  File "/home/giovanni/git/ozzy-backend/venv/lib/python3.6/site-packages/django/utils/version.py", line 6, in <module>
    from distutils.version import LooseVersion
  File "/home/giovanni/git/ozzy-backend/venv/lib/python3.6/distutils/__init__.py", line 25, in <module>
    from distutils import dist, sysconfig
  File "/usr/lib64/python3.6/distutils/dist.py", line 10, in <module>
    from email import message_from_file
ImportError: cannot import name 'message_from_file'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 34, in <module>
    ) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

And removing it my app runs fine. Can you help me with this issue?
This has something to do with the email package?

Django: 2.1.2
Python: 3.6
Using virtualenv.

@giovannicimolin giovannicimolin changed the title Doesn't work with Python 3 cannot import name 'message_from_file' Oct 18, 2018
@anx-ckreuzberger
Copy link
Contributor

anx-ckreuzberger commented Oct 19, 2018

Hi!

This issue seems to be coming from your virtualenv and/or package manager itself, not from django-rest-passwordreset.

Are you using virtualenv or pipenv? Is this happening with the latest version of django-rest-passwordreset (0.9.6) or also with older versions (e.g., 0.9.5)?

How are you installing the package? (using pip install django-rest-passwordreset?)

edit: What version of pip are you using (pip --version)? Can you also do a pip freeze please?

@anx-ckreuzberger anx-ckreuzberger self-assigned this Oct 19, 2018
@giovannicimolin
Copy link
Author

Hi!

I'm creating the virtualenv like this virtualenv venv -p python36.
To use the virtualenv, I either use direnv with a .envrc file containing

source venv/bin/activate

I've installed the package using pip install django-rest-passwordreset.

pip Version: 10.0.01
I'm using Django 2.1.2.
I can't do a pip freeze right now because I'm traveling.
Weird thing is when I remove django-rest-passwordreset from my project it works fine.

Maybe it's a problem with my e-mail backend configuration?

# E-mail settings
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = credentials.EMAIL_DEFAULT_FROM
SERVER_EMAIL = credentials.EMAIL_SERVER
EMAIL_HOST = credentials.EMAIL_HOST
EMAIL_PORT = credentials.EMAIL_PORT
EMAIL_HOST_USER = credentials.EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = credentials.EMAIL_HOST_PASSWORD

@giovannicimolin
Copy link
Author

Some dependency on django-rest-passwordreset breaks Python on my entire system.

I'm using Arch Linux with Python 3.7 on system and Python 3.6 on the virtualenv, when I run pip install django-rest-passwordreset something happens all Python installs I have break.

I've tried on 2 computers and reinstalled my system and the problem still happens (guess who going to reinstall his system again 😢).

@anx-ckreuzberger
Copy link
Contributor

This should really not be the case at all. In addition, a package that you install in a virtualenv should not (and actually can not) break your system python installation (if it does, then something else is really wrong with your virtualenv or python installation...).

We're using this library heavily on debian and Ubuntu systems, and have never had an issue like this before.
Also, the library itself does not install any dependencies etc..., nor does it have any requirements on other libraries (obviously, it is expected that you have django and django rest framework installed).

Is it possible that your virtualenv version is quite old? Can you do a

virtualenv --version

and if possible upgrade virtualenv on your system before you install the project and dependencies?
Also, if you are using a virtualenv anywhere on your system make sure to re-generate the whole virtualenv before you continue.

@giovannicimolin
Copy link
Author

giovannicimolin commented Oct 25, 2018

I get this error using virtualenv, pyenv and even with a isolated Python install, but it only happens after I run:

pip install django-rest-passwordreset
# Then add django_rest_passwordreset to installed apps
python manage.py migrate

After this, doesn't matter what version of python 3 that I'm using, it breaks and gives this error:

Traceback (most recent call last):
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/__init__.py", line 16, in setup
    from django.urls import set_script_prefix
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/urls/__init__.py", line 1, in <module>
    from .base import (
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/urls/base.py", line 8, in <module>
    from .exceptions import NoReverseMatch, Resolver404
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/urls/exceptions.py", line 1, in <module>
    from django.http import Http404
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/http/__init__.py", line 2, in <module>
    from django.http.request import (
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/http/request.py", line 14, in <module>
    from django.http.multipartparser import MultiPartParser, MultiPartParserError
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/http/multipartparser.py", line 9, in <module>
    import cgi
  File "/home/giovanni/.pyenv/versions/3.6.6/lib/python3.6/cgi.py", line 39, in <module>
    from email.parser import FeedParser
ModuleNotFoundError: No module named 'email.parser'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 35, in <module>
    execute_from_command_line(sys.argv)
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/management/__init__.py", line 350, in execute
    _parser = self.fetch_command('runserver').create_parser('django', 'runserver')
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/management/__init__.py", line 224, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/management/__init__.py", line 36, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/home/giovanni/.pyenv/versions/3.6.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 10, in <module>
    from django.core.servers.basehttp import (
  File "/home/giovanni/.pyenv/versions/hidros/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 14, in <module>
    from wsgiref import simple_server
  File "/home/giovanni/.pyenv/versions/3.6.6/lib/python3.6/wsgiref/simple_server.py", line 13, in <module>
    from http.server import BaseHTTPRequestHandler, HTTPServer
  File "/home/giovanni/.pyenv/versions/3.6.6/lib/python3.6/http/server.py", line 90, in <module>
    import email.utils
ModuleNotFoundError: No module named 'email.utils'

The error stays even after I uninstall django-rest-passwordreset and only stops happening when I set up a fresh python installation.

Virtualenv version: 16.0.0
pyenv-virtualenv 1.1.3 (conda conda 4.5.11)
pyenv versions:

  system
  3.6.6
  3.6.6/envs/proj
* proj (set by PYENV_VERSION environment variable)

Pip freeze before installing django-rest-passwordreset:

argcomplete==1.9.3
atomicwrites==1.1.5
attrs==18.1.0
autopep8==1.3.5
backcall==0.1.0
base58==1.0.0
boto3==1.7.38
botocore==1.10.38
certifi==2018.4.16
cfn-flip==1.0.3
chardet==3.0.4
click==6.7
Collectfast==0.6.2
coreapi==2.3.3
coreschema==0.0.4
coverage==4.5.1
decorator==4.3.0
dj-database-url==0.5.0
Django==2.1.2
django-cors-headers==2.2.0
django-crispy-forms==1.7.2
django-extra-fields==1.0.0
django-fieldsignals==0.3.4
django-filter==2.0.0
django-filters==0.2.1
django-rest-passwordreset==0.9.7
django-sequences==2.2
django-silk==3.0.1
django-storages==1.6.6
djangorestframework==3.8.2
djangorestframework-gis==0.13
djangorestframework-jsonapi==2.4.0
djangorestframework-jwt==1.11.0
docutils==0.14
drf-nested-routers==0.90.2
drf-yasg==1.8.0
durationpy==0.5
Faker==0.8.8
future==0.16.0
gprof2dot==2016.10.13
hjson==3.0.1
idna==2.7
importmagic==0.1.7
inflection==0.3.1
ipdb==0.11
ipython==6.5.0
ipython-genutils==0.2.0
isort==4.3.4
itypes==1.1.0
jedi==0.12.1
Jinja2==2.10
jmespath==0.9.3
kappa==0.6.0
lambda-packages==0.20.0
MarkupSafe==1.0
mixer==6.0.1
more-itertools==4.3.0
openapi-codec==1.3.2
parso==0.3.1
pexpect==4.6.0
pickleshare==0.7.4
Pillow==5.1.0
placebo==0.8.1
pluggy==0.7.1
postgis==1.0.4
prompt-toolkit==1.0.15
psycopg2-binary==2.7.4
ptyprocess==0.6.0
py==1.5.4
pycodestyle==2.4.0
Pygments==2.2.0
PyJWT==1.6.4
pytest==3.7.1
pytest-cov==2.5.1
pytest-cover==3.0.0
pytest-coverage==0.0
pytest-django==3.3.3
python-dateutil==2.6.1
python-decouple==3.1
python-slugify==1.2.4
pytz==2018.4
PyYAML==3.12
requests==2.19.0
ruamel.yaml==0.15.38
s3transfer==0.1.13
simplegeneric==0.8.1
six==1.11.0
snakeviz==1.0.0
sqlparse==0.2.4
text-unidecode==1.2
toml==0.9.4
tornado==5.1
tqdm==4.19.1
traitlets==4.3.2
troposphere==2.3.0
Unidecode==1.0.22
uritemplate==3.0.0
urllib3==1.23
wcwidth==0.1.7
Werkzeug==0.14.1
wsgi-request-logger==0.4.6

@giovannicimolin
Copy link
Author

giovannicimolin commented Oct 25, 2018

Doesn't seem to be exactly a problem on your lib, but triggered from it.

When I have a little more time I'll try to make a repo to reproduce this issue.

@anx-ckreuzberger
Copy link
Contributor

Hi! I'm wondering if you came across this issue again (or if you found a solution to it, other than not using this package)?

@saurabhchandrapatel
Copy link

saurabhchandrapatel commented Mar 2, 2019

I am also getting same msg with import pandas as pd in django web application

but in pip freeze does not have django_rest_passwordreset package

Traceback (most recent call last):
File "parsing.py", line 2, in
import pandas as pd
File "/mnt/c/srv/python/development/yoga/env/lib/python3.5/site-packages/pandas/init.py", line 23, in
from pandas.compat.numpy import *
File "/mnt/c/srv/python/development/yoga/env/lib/python3.5/site-packages/pandas/compat/init.py", line 32, in
from distutils.version import LooseVersion
File "/mnt/c/srv/python/development/yoga/env/lib/python3.5/distutils/init.py", line 26, in
from distutils import dist, sysconfig # isort:skip
File "/usr/lib/python3.5/distutils/dist.py", line 10, in
from email import message_from_file
ImportError: cannot import name 'message_from_file'

@anx-ckreuzberger
Copy link
Contributor

@giovannicimolin @saurabhaec Do you happen to have a file called "email.py" (or a folder called "email") somewhere within your project?

@rinshankolayil
Copy link

rinshankolayil commented Aug 6, 2019

I got this problem, I have tried to run sever through virtual env as follows
django runserver 0.0.0.0:8000.

this seems to be working.

when I am trying with apache (by http with port 80) it seems to be not working.

I think the error due to not able to import library from site_packages. Try on checking python path given in apache2 configuration because it works with django runserver method.

@anx-ckreuzberger
Copy link
Contributor

@rinshankolayil do you happen to have a file called "email.py" or a folder called "email" somewhere within your project?

@rinshankolayil
Copy link

@anx-ckreuzberger : Aah may be there is one. I will check and tell you.Anyway thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants