I've run into a very odd problem with django-registration, and I'm sort of at a loss for how to proceed. On my local development machine running OS X 10.8.2, python 2.7.2 and virtualenv 1.8.2, I'm working with django-registration 0.8 and a hacked up version of django-email-usernames 1.0, (which was having some problems with django-registraiton 0.8). Everything works perfectly, and I get no errors.
On my dev server, if I try to login or register a new account, I get the following error:
ImproperlyConfigured
Error importing authentication backend *site-name*registration.backends.EmailOrUsernameModelBackend: "No module named backends.default"
I believe the relevant code is:
from registration.backends.default import DefaultBackend
class EmailOrUsernameModelBackend(DefaultBackend):
The only difference between the two environments is the OS and python version on the staging server, (Debian Squeeze and 1.66 respectively). I'm not sure how it's possible that the exact same package versions supporting the exact same codebase are experiencing totally different behaviors. I'd be grateful for any insight anyone can lend.
Just in case there is any useful information therein, here is the pythonpath on my remote machine:
['/usr/local/*virtualenv*/*site-name*', '/usr/local/*virtualenv-name*/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg', '/usr/local/*virtualenv*/lib/python2.6/site-packages/pip-0.7.2-py2.6.egg', '/usr/local/*virtualenv*/lib/python2.6', '/usr/local/*virtualenv*/lib/python2.6/plat-linux2', '/usr/local/*virtualenv*/lib/python2.6/lib-tk', '/usr/local/*virtualenv*/lib/python2.6/lib-old', '/usr/local/*virtualenv*/lib/python2.6/lib-dynload', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib64/python2.6/lib-tk', '/usr/local/*virtualenv*/lib/python2.6/site-packages', '/usr/local/*virtualenv*/lib/python2.6/site-packages/PIL']
Something else odd that I have noticed: from registration.backends.default import DefaultBackend works fine in the shell.
Related
I had to install new package on my project to handle with Base64 images from my API, so i installed django-extra-fields, so far so good, i have made my testes locally, everything working just fine, when i pushed my changes to production and installed the new package running pip install django-extra-fields with right virtualenv on, i just keep getting the error ImportError at /
No module named drf_extra_fields.fields
That seens a silly mistake, so i checked my code like 100 times so far, and everything is right
I'm using Django 1.11 with Python 2.7
My vm is called: vm-prod_cfr_nuvem
When i run pip freeze show all my packages:
(vm-prod_cfr_nuvem) [~ site-packages]$ pip freeze
Django==1.11.6
django-cors-headers==2.1.0
django-extra-fields==2.0.2
django-filter==1.1.0
And if i enter in vm site-packages path, i can see that is installed there
/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib/python2.7/site-packages
django_cors_headers-2.1.0.dist-info
django_extra_fields-2.0.2.dist-info
django_filter-1.1.0.dist-info
on my view where the show the error, as you can see, is the same path as the last one in list
ImportError at /
No module named drf_extra_fields.fields
...
Python Path:
['/home/daniloitj/webapps/cfr_prod/lib/python2.7/Django-1.11.9-py2.7.egg',
'/home/daniloitj/webapps/cfr_prod',
'/home/daniloitj/webapps/cfr_prod/cfr_nuvem',
'/home/daniloitj/webapps/cfr_prod/lib/python2.7',
'/home/daniloitj/lib/python2.7',
'/home/daniloitj/lib/python2.7',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib64/python27.zip',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib64/python2.7',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib64/python2.7/plat-linux2',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib64/python2.7/lib-tk',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib64/python2.7/lib-old',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7',
'/usr/lib/python2.7',
'/usr/lib64/python2.7/lib-tk',
'/home/daniloitj/.virtualenvs/vm-prod_cfr_nuvem/lib/python2.7/site-packages']
Obs.: I thought that somehow my server is not using my VM or something like it... so i activate it manually on my terminal and run python manage.py shell and tried to import the lib import drf_extra_fields im still getting the same error
Obs2.: Didnt found anyone with same problem using that lib, and there is no issues about it, so probabily is my misconfiguration rather than something broke in the lib
Package Page: https://github.com/Hipo/drf-extra-fields
That error make me crazy... i solved it going back 1 small version... so instead of using 2.0.2 i'm using 2.0.1, the odd thing is... the 2.0.2 still working on my local environment, but dont work on production, and dont seems be environment problem cuz my server match all requirements to use that lib
I'm far from Python expert, so please bear with me.
I'm using Slack python bot library, which utilizes module loading to execute users code.
I noticed a weird thing - when I launch my script, it says ImportError: Import by filename is not supported on a line self.module = __import__(name) (where name is relative path to the Python file). I don't quite understand the problem, because the owners of the library test their code with both 2.x and 3.x Python, and it DOES work on TravisCI.
I'm using Python 2.7.8 on Windows 7.
How do I fix the problem? I suspect something on my system is wrong. I read similar questions on SO and worked around the issue by using imp.load_source, but I would like to get to the bottom of it.
P.S. It also works if I upload it to Heroku, which by default runs 2.7.12
I have pulled some working Django code from a repo and am trying to set up my local windows 7 dev environment. I have what I think is a suitable version of Python (2.7.6) and a copy of Django 1.5.4.
When I tried python manage.py runserver, I got various ImportErrors.
One by one, I did a pip install XXXX and they went away.
But now I am stuck with this error;
ImportError: cannot import name parse_html_config
I'm only a few days into Python & Django so am unclear - but I think this import is part of commandtools package, so I did pip install commandtools. I got the message that commandtools was already installed.
When I search my project, I can't find from XXXX import parse_html_config anyway, so I don't know where to look next, can anyone help please?
The whole output is;
(swoopenv) C:\django workspace\swoopenv\swoop\swoop>python manage.py runserver
C:\Python27\Lib\site-packages\django\core\management\__init__.py:465: DeprecationWarning: The 'execute_manager' function is deprecated, you
likely need to update your 'manage.py'; please see the Django 1.4 release notes (https://docs.djangoproject.com/en/dev/releases/1.4/).
DeprecationWarning)
C:\Python27\Lib\site-packages\django\core\management\__init__.py:409: DeprecationWarning: The 'setup_environ' function is deprecated, you li
kely need to update your 'manage.py'; please see the Django 1.4 release notes (https://docs.djangoproject.com/en/dev/releases/1.4/).
DeprecationWarning)
C:\Python27\Lib\site-packages\django\conf\__init__.py:221: DeprecationWarning: You have no filters defined on the 'mail_admins' logging hand
ler: adding implicit debug-false-only filter. See http://docs.djangoproject.com/en/dev/releases/1.4/#request-exceptions-are-now-always-logge
d
DeprecationWarning)
ImportError: cannot import name parse_html_config
I've found a lot of posts on Macports/Django install issues but none seem to quite address my situation.
Installed Django using Macports from the command line using
sudo port install py27-django
This seemed to work fine. I opened up IDLE and was able to import django. The following bit of code
import django
from django.core import management
print django.VERSION
returns
(1, 5, 1, 'final', 0)
Which I take to mean I have the final version of Django 1.5.1 installed. So, all seems to be well.
However, now I switch over to my Django tutorial to get learning and I am asked to type this into the command line to confirm that Django is installed:
python -c "import django; print(django.get_version())"
and get the following error:
> File "<string>", line 1, in <module> ImportError: No module named
> django
Some other bits of data. Here's my $PATH:
/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
Finally, the command
django-admin.py startproject mysite
returns
-bash: django-admin.py: command not found
But the command
django-admin-2.7.py startproject mysite
works (creates a new directory called mysite in the working directory). I read somehwere that Macports renames the django-admin file.
I've only been working with Unix for a few weeks so this is a bit confusing. It seems like I have Django on my system, but perhaps the python I am trying to access from my command line is a different python from that which Macports uses.
Any help appreciated!
Dennis
You will need to set your PYTHONPATH environment variable from your terminal to reference your django install. IDLE probably did this for you, but in another shell you'll need to set it. You can set it in your terminal permanently by setting it in ~/.bashrc or ~/.bash_profile (or whatever your terminal shell is).
Your PATH starts with /Library/Frameworks/Python.framework/Versions/2.7/bin so when you type python you get the python in that directory which is the Apple supplied one nut you have installed Django for the Macports one so python does not see it.
To fix you need to have /opt/local/bin earlier on the path than the /Library one. even better remove that /Library entry and use port select python ... to choose which python to run the Macports 2.7 or Apple's or others
As for the django-admin-2.7.py issue, Macports allows you to have several versions of python at once so code depending on eth version has the version add into the script names e.g. you could have a django-admin-2.6.py as well if you installed the py26-django package. This also applies to python itself however python also adds into the port select mechanism so you set a default version.
I've upgraded to PyCharm 2.5 and in the meantime upgraded django-templated-email to version 0.4.3.
Now, Django unit tests do not longer work through PyCharm, as I'm getting the error ImportError: cannot import name send_templated_mail in the test console output.
When running the same test in the console, this error does not appear. I have the feeling that it has something to do with send_templated_email being part of templated_email\__init__.py (I vaguely remember a similar issue once, but cannot for the life of me remember how I fixed it).
The settings in the test dialog are:
Target: <django app name>
Custom settings: <path to dev settings>
Environment variables: PYTHONPATH: <path as set in virtualenv>
Python interpreter: <virtualenv Python interpreter>
Interpreter options: None
Working directory: <path to Django project (where manage.py resides)>
The strange thing is that the code inspection inside the IDE does not complain and loads the templated_email module correctly through from templated_email import send_templated_mail.
I'm using Windows 7, and my Django app is running inside a virtualenv (which is correctly being recognized by PyCharm).
I would suggest upgrading to version 4.5.x if you haven't already. It fixes lots of bugs and has several improvements.
Also, if you think this is a bug in PyCharm, check out their bug tracking/filing site:
https://youtrack.jetbrains.com/issues