After installing Django version 1.9 in a virtual environment using the following command in Windows:
django-admin --version
I receive a long error, ending with:
File "C:\Users\DELL\env\Lib\site-packages\django\db\models\sql\query.py", line 11, in <module>
from collections import Counter, Iterator, Mapping, OrderedDict
ImportError: cannot import name 'Iterator' from 'collections' (C:\Users\DELL\AppData\Local\Programs\Python\Python311\Lib\collections\__init__.py)
Python is installed, and the virtual environment was activated.
Django was installed using pip install django==1.9
What should I do to run the command django-admin --version?
Django 1.9 requires Python 2.7, 3.4, or 3.5..make sure you have installed python version from one of these..
(I have copied the answer that I got)
You are using a very old version of Django and, as a result, your Python is incompatible with it. Django is trying to import Iterator from a Python module, but it was moved long ago from collections to collections.abc and that is why it gives you the ImportError.
You can either upgrade you Django to the current version or change your Python to below version 3.3
Related
I know that many have posted similar question however I tried most solution without success.
I'm trying to host a webpage with apache2 and django in python3.
In the error log I found ImportError: No module named 'django' when accessing the wsgi.pyfile, where I also added import sys, sys.version to confirm which python version is used and from the error log I can see that I'm running following python version 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609].
When I run python3.5 I see that I uses the same python version and here I can run import django without any error!
EDIT: I checked django.__file__and saw that it was located in /home/USERNAME/.local/lib/python3.5/site-packages/django/init.py and that path /home/USERNAME/.local/lib/python3.5/site-packages wasn't in the sys.path that tried to run django. But adding it with sys.path.append(path) didn't help :(
Any thoughts what I might have messed up?
If you have Setup the whole configuration in VirtualEnv then , i suggest you to activate it by,
source /location to /env/bin activate
pip3 install django=version_id
or pip install django=version id
if you want to pass version id then its good or it will install the latest django from your repo.
Now test Django Version there.
Hope you will no get the error.
Location - means the path where env will be located in project directory, if you have followed the standard installation process of django or else you don't need, and version id- vesion of django framework.
I finally understood how to solve it! first I had to run pip3 uninstall django then run sudo pip3 install django.
I was using Django 1.8 and I wanted to upgrade to the latest version (1.11.6). When I did that I got this error message when trying to run the development server:
from django.utils.deprecation import RemovedInDjango19Warning
ImportError: cannot import name RemovedInDjango19Warning
I can uninstall django and run pip install django=1.9 but I want to keep the latest version. Any tip of how to solve that? Thanks!
PS: I'm running python 2.7.13
The problem was actually in python 2.7.
Reinstalling Python 2.7 solved the issue.
How did I came up with the solution?
I tried python3 manage.py runserver instead of python manage.py runserver and the server worked (but with problems of course since I was using print x instead of print(x) So I knew there was something up with python not django.
I have installed Django after activating my virtualenv but still I am getting following error
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
If you already activated your virtualenv (source /path/bin/activate) then check if you have installed Django.
pip install django
With next command you can see if Django was installed.
pip freeze | grep django
Another thing that you can try is to remove first line (#!/usr/bin/env python) in the manage.py file.
You should check if django is installed
Activate your environment, then run the following command to see which version is installed :
python -c "import django; print(django.get_version())"
I am using virtual environment so I added this line in manage.py:
sys.path.append('./myvenv/lib/python3.5/site-packages')
in which myvenv is the name of my virtual environment and version of my installed Python is 3.5.
This solved my issued.
I found that I had Python 3.4 and 2.7 installed concurrently, and the pip install django==1.7 command automagically decided the Python 3.4 /dist-packages was where it should live. I CD'd over to the Python 2.7 directory and re-piped it... and all is well.
sudo pip install django --upgrade
worked for me, i am not having virutal environment by the way.
I had the same problem when I was running Django from inside a virtual environment and then using another terminal window ran the command
python manage.py shell without first switching to the venv.
The problem was resolved after I switched back.
I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.
I confirmed that I was using the python interpreter in my virtual environment.
I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.
If you're using virtualenv, you can add it to your path using sys.path.append('./myvenv/lib/python3.5/site-packages').
Try closing and opening the terminal again. That worked for me too.
Hi I am getting this error while I am trying to run syncdb in my virtual environment.
If I copy psycopg2 folder to my project folder (where I have my manage.py and settings.py) then this error disappears. But I still get this error when the code is pushed to heroku.
I have referred to many online materials but wasn't very lucky.
File "c:\Users\mayayadav\anteus\venv\lib\site-packages\psycopg2-2.4.5-py2.7-wi
n32.egg\psycopg2\__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: The specified module could not be found. (venv)
I had the same problem on Windows, The way i get it working was to install psycopg2 from:
http://www.stickpeople.com/projects/python/win-psycopg/
And doing it this way it's recomended here http://initd.org/psycopg/install/
In the case, where the install binaries are not up to date (as it happened today: latest Python is 3.4 and PostgresSQL - 9.3, while latest avaiable are 3.3 and 9.2.6 respectively), it is enough to add the PostgresSQL binary path (e.g. C:\Program Files\PostgreSQL\9.3\bin) to the path variable.
Note: you need to restart your command line to get it working.
2019 Update
I encountered the same issue with Python 3.8 and psycopg2 2.8.3 and 2.8.4. Apparently psycopg2 doesn't work with Python 3.8 yet (understandably, since 3.8 released very recently). The fix for me was to go back to using Python 3.7.
It's so old problem... I ran into a problem with PyCharm and virtualenv, PyCharm have problem with pip install psycopg2. I copied _psycopg.cp38-win_amd64.pyd from global python to \venv\Lib\site-packages\psycopg2. And all done.
I installed python 2.6 alongside my mac's 2.5.2 version. As soon as I did, python2.6 manage.py runserver failed because it couldn't find django.core.management.
From a shell, import django returns importerror: No module named django.
Why?
Did you reinstall Django?
This happens when I install side by side versions of Python on Gentoo. Whenever I install a new version, I have to either reinstall the new ones or make a symlink to the old site-packages.
Because each installation of Python uses its own directory to store libraries. On a Mac, they are in /Library/Python/2.x/site-packages/. Presumably you originally installed Django in the 2.5 directory, but it isn't yet in the 2.6 one. You can symlink it there if you want to, or reinstall it using the new version.
Add site-packages to PYTHONPATH:
export PYTHONPATH="/home/jerome/bin/django-1.1/lib/python2.6/site-packages:$PYTHONPATH"
Worked on Ubuntu, with a python/django virtual environment using virtualenv and pip.
Source: http://benfsayer.com/importerror-no-module-named-django-core-management/
I use Bitnami's Django installer, and this happened for me when I wasn't in their custom shell, which I believe sets related python path environment variables. I ran ./use_djangostack in the root of the Bitnami package and then was successful running the server again.