Python-Django: ImportError: no module named django - python

Im completely new to django and Ive been trying to set up an environment from here [https://docs.djangoproject.com/en/1.1/intro/tutorial01/]. Python was already setup on my mac
Python 2.7.2. I followed the instructions and setup django using
sudo port install py27-django
And also added /etc/paths.d/macports with
/opt/local/bin
/opt/local/sbin
/opt/local/lib/python2.7/site-packages/django/bin
But I still get the ImportError: No module named django message when I import django from the python shell.
I looked at this link
importerror: No module named django but it didnt really help much. Any help is appreciated

Have a look at this article... they are using virtualenv to set up the project and this fixed a lot of problems like this for me. With virtualenv, the system libraries and the libraries you need for your python project are separated, so your not mangling them together.
http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/

If I may, it looks like the last path you added was pointing to a python2.4 directory, you might need to look for django in a python2.7 directory instead.

Related

manage.py createsuperuser: AttributeError: module 'os' has no attribute 'PathLike'

I'm trying a Django tutorial. For some reason my existing superuser got deleted; creating that went fine, but I can't make another one. This also happens when I try to use pip.
I didn't change anything in the libraries so not sure why this happens now but didn't before. On windows 7 (Python 3.6.3 and Django 1.11). I've seen similar but not the exact same problems for Windows. Still I checked the file and there seems to be a PathLike class.
I've also tried to repair my Python installation but it didn't help. any ideas?
Seems like you may have modified the settings.py file. But as MrName mentioned you need to share full stack trace
This looks like a feature that changed in Python3.6 as you can see here. Make sure that your python version is 3.6 or greater.
Update your Python and Django version and that will work perfect.
AttributeError: module 'os' has no attribute 'PathLike'
Installing it into the global site-packages with the below command solved my problem:
pip install --user virtualenvwrapper

importerror: No module named django in windows 7

I have looked into post with the same problem as mine but never got lucky to find solution of mine. I have installed python 3.4.1 and and install django through git. I have also set my environment variable PATH to C:\Python34\Scripts but everytime I type django-admin --version in my command promt, it says not recognize as internal or external command and when using python shell when I type import django it says importerror: No module named django. What am I missing here? Please help. Thanks a lot.

Django with VS2010 gives me "ImportError: No module named django.core.management" when running

I'm trying to follow this tutorial and I'm getting the following error:
ImportError: No module named django.core.management
I'm completely new to python. I believe Visual studio is using a version of python I already had installed in c:\Python27, could that be causing a problem?
Someone mentioned in a link I found that they had to copy the 'django' folder to the project folder, but I don't know where that would be. I don't even know what the error means really unless there's a missing package (like dll or assembly in .NET?), but I don't know what paths python would use to try to find a package or even what one would look like.
I see there's a PYTHONPATH environment variable that I don't have declared, should I declare that? Should it point to the C:\Python27 directory?
First, do you have checked your "Python Environment" in your project folder? It may seems like...
Here you may find your django with version. If you dont find it then compile setup.py from django folder again with desire python version. And then right click on "Python Environments" from your project and click on "Add/Remove Python Environments" to select python version.
Ok with a lot of fooling around I found this directory:
%LOCALAPPDATA%\Microsoft\Web Platform Installer\installers\PythonDetectInstalls
In a mangled sub-folder there is a powershell script DetectPythonInistalls.ps1 that has these two lines for checking if python is installed already:
$regKey = "hklm:SOFTWARE\Python\PythonCore\$pythonVersion\InstallPath";
$correctRegKey = "hklm:SOFTWARE\Wow6432Node\Python\PythonCore\$pythonVersion\InstallPath";
Uninstalling all my pythons did not remove these keys. After removing these registry keys with regedit, WPI allowed me to install its own version of python 2.7 and all the other goodies to go with the Windows Azure Python SDK and it worked.

Running django-admin.py startproject is giving me an error

I've just started looking into python and django.. Im pretty sure ive successfull installed both python and the django framework and i managed to add python and django-admin.py to my system path but now when i run the command django-admin.py startproject My_Test_Site, in the folder i want to create a new project directory in (just following the tutorials), i get the following error:
What am i doing wrong?
This is not a Django error. It appears it cannot find the Python module unicodedata which is part of the Python Standard Library (docs). I see that there is also a bug report about this issue (Python 2.7 on Windows, see here). On the other hand, some people there report that reinstalling their Python installation fixed the problem. You could give that a try.
notice the last line, it says import unicodedata, importError
im guessing you probably didnt install your django properly.
so reinstall it and check that django is in your "path", i believe django does this automatically when it installs but doesnt hurt to double check.
if reinstalling django still doesn't work, i suggest you uninstall python and django related stuff.
then install python, install pip, then use pip install django.

Dajaxice Autodiscover in Django App (cannot import name dajaxice_autodiscover)

I was following the directions at http://django-dajaxice.readthedocs.org/en/latest/installation.html to install Dajaxice for simple AJAX support and I ran into an error I can't quite figure out. The lines:
from dajaxice.core import dajaxice_autodiscover
#dajaxice_autodiscover()
in urls.py seem to be causing an error (cannot import name dajaxice_autodiscover). When I look at the module files for Dajaxice I don't see one for autodiscover either. If I leave out these lines, will I have any troubles using dajaxice? Thanks.
The import should be correct like that! dajaxice_autodiscover imported in __init.py__ of the core package, so it is supposed to work like that! More likely the whole app is probably installed in a wrong path, you could try to open a shell (python manage.py shell) and try import dajaxice and see what happens!
William What version of dajaxice do you have? the "registration approach" documented in github wiki work with dajaxice>=0.1.5
For older versions of dajaxice you should register your functions in settings.DAJAXICE_FUNCTIONS.
Anyway newest versions of dajaxice has less bugs.
It looks like the wiki installation instructions are ahead of the available downloads. If you pull the latest version of the code from git and install that then the instructions work. I'm not sure how to install versions 1.4 and below though.
I experienced the same problem and I found the solution.
It all about environment vairables in windows. You set following via CMD:
set DJANGO_SETTINGS_MODULE 'Your django project/your site/settings.py
Now it should work fine, Good Luck!

Categories