Ok, I see plenty of these errors around. I have tried everything I know to do and have yet to figure this out.
I am working on a development server running python 2.5 and Django 1.3. Django 1.3 was installed using python setup.py install after unpacking the tar.gz download.
All works well, I seldom have the need to run
manage.py but am trying to use the new staticfiles app and am running into problems.
python manage.py collectstatic Traceback (most recent call last): File "manage.py", line 2, in <module> from django.core.management import execute_manager ImportError: No module named core.management
Ok, so I have
From Django install I double check my
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" /usr/lib/python2.5/site-packages
Ok, let’s check out what I have, echo $PYTHON_PATH was empty, so I set it
Still no luck. Lets check what sys.path has to say
>>> import sys >>> print sys.path ['', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/site-packages/django', '/var/lib/python-support/python2.5']
path is there, I even created /usr/lib/python2.5/site-packages/django.pth with contents
cat /usr/lib/python2.5/site-packages/django.pth /usr/lib/python2.5/site-packages/django/
Anyone got an clues to what is going on here?
I found a symlink further up the path that was getting in the way, but no on to a new error.
python manage.py collectstatic Traceback (most recent call last): File "manage.py", line 14, in <module> execute_manager(settings) File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 349, in execute version=get_version(), File "/usr/lib/python2.5/site-packages/django/__init__.py", line 12, in get_version from django.utils.version import get_svn_revision ImportError: No module named utils.version
I also tried creating a new project to see if there were any issues there and get the same utils.version error.
Side node: Unode from #django helped me a bit, set up virtualenv on same machine and got past the errors so still not sure what is up with this actual install here, but it seems to not be in the django projects but in the django/python install.
If, like me, you are running your django in a virtualenv, and getting this error, look at your
The first line should define the python executable used to run the script.
This should be the path to your virtualenv’s python, but it is something wrong like /usr/bin/python, which is not the same path and will use the global python environment (and packages will be missing).
Just change the path into the path to the python executable in your virtualenv.
You can also replace your shebang line with
#!/usr/bin/env python. This should use the proper python environment and interpreter provided that you activate your virtualenv first (I assume you know how to do this).
If you are in a virtualenv you need to activate it before you can run ./manage.py ‘command’
if you config workon in .bash_profile or .bashrc
*please dont edit your manage.py file maybe works by isnt the correct way and could give you future errors
I had the same problem because I was installing Django as a super user, thus not in my virtualenv. You should not do
sudo pip install Django
Instead, install it this way:
$ source ./bin/activate $ pip install Django
Please, reinstall django with pip:
sudo pip install --upgrade django==1.3
(Replace 1.3 to your django version)
As known this was a path issue.
the base of my custom packages shared a name with a directory set in a /etc/profile. The packages were in a different location however for the webserver. So I removed the offending entries from my $PYTHONPATH and was good to go!
Thanks for the help.
another possible reason for this problem is, that your OS runs python3 by default.
either you explicitely do:
or you edit the shebang of manage.py, like so:
I had this error while trying to run an embedded system (using django of course) on a Raspberry Pi 2 (and not a VM)
sudo pip install Django
Made the trick!
- just in case a fellow using Raspbian/Jessie gets this
For me, my server was using Python 2.4. I simply looked up Python 2.7, which was installed on my server, and created an alias.
If you need to know more, I found the solution here
You are probably using virtualenvwrapper. Don’t forget to select your enviroment by running:
$ workon env_name
Try change your first line of manage.py.
I was getting the same problem while I trying to create a new app. If you write
python manage.py startapp myapp, then it looks for usr/bin/python. But you need this “python” which is located in /bin directory of your virtual env path. I solved this by mentioning the virtualenv’s python path just like this:
<env path>/bin/python manage.py startapp myapp
After searching for ages and trying all these other suggestions which didn’t work, I finally found the solution for my setup.
- Windows, Python27
- My django project is checked out via svn
- when running python manage.py runserver in the new folder, I got the import error
- python manage.py runserver used to work in the original folder (which I would commit changes from) until I deleted it
Remove any the folder named django in the same directory of manage.py
Thats right…as soon as I removed the folder “django” which only contained a initt.py file…I could run the server again!
Have no idea why though
Store the python python path in a variable and execute.This would include the otherwise missing packages.
python_path= `which python` $python_path manage.py runserver
I had a similar problem. PyCharm couldn’t run the server but I could run it from the command line. I tried which python and then made sure that PyCharm was same interpreter and then everything worked OK.
This error usually occurs when django is not installed.
If you have already installed django but still getting the same error, then you must be working in separate virtual environment. You need to install django in your virtual environmnent as well. When you are in shell of virtual machine simply do this:
pip install django
It is because virtual machine has separate file system, it doesn’t recognize django even if it is installed on your system.
I fixed this problem by changing #PATH=”$VIRTUAL_ENV/bin:$PATH” to PATH=”$PATH:$VIRTUAL_ENV/bin”
For reasons not obvious to me the python executable in the virtualenv dir does not see django but the normally installed python does.
your project is created using an old version of django-admin.py, older than django1.3
to fix this create another django project and copy its manage.py and paste it in the old one
Agreed completely that this is a path issue but fwiw, I had this same error. It was due to the mistake of using a relative path for my Python executable when setting up my virtual environment. I had done this:
virtualenv -p ~/python_runtimes/2.7.3/bin/python venv2.7.3 --distribute
Instead I had to give the full path to the Python executable.
pick your virtualenv to replace “blog-venv” here.
Be sure you’re running the right instance of Python with the right directories on the path. In my case, this error resulted from running the
python executable by accident – I had actually installed Django under the
python2.7 framework & libraries. The same could happen as a result of virtualenv as well.
Okay so it goes like this:
You have created a virtual environment and django module belongs to that environment only.Since virtualenv isolates itself from everything else,hence you are seeing this.
go through this for further assistance:
1.You can switch to the directory where your virtual environment is stored and then run the django module.
2.Alternatively you can install django globally to your python->site-packages by either running pip or easy_install
Command using pip: pip install django
then do this:
print (django.get_version()) (depending on which version of python you use.This for python 3+ series)
and then you can run this:
python manage.py runserver
and check on your web browser by typing :localhost:8000
and you should see django powered page.
Hope this helps.
I included the name of the new App to the INSTALLED_APPS list in the settings.py “before” I issued the startapp command. Once I removed the list entry, I could create the app.
I solved this problem by using ‘django-admin’ command as following instead:
django-admin startproject _project_name
just remove the “.py” attached to “django-admin”
python3 manage.py runserver
Check version of Python
all of you guys didn’t mention a case where someone “like me” would install django befor installing virtualenv…so for all the people of my kind ther if you did that…reinstall django after activating the virtualenv..i hope this helps