Import error cannot import name execute_manager in windows environment
Asked Answered
K

3

38

I'll get you up to speed. I'm trying to setup a windows dev environment. I've successfully installed python, django, and virtualenv + virtualenwrapper(windows-cmd installer)

workon env
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1,6,1, 'final',0)
>>> quit()

But when I run: python manage.py runserver from my cloned repository I get this error:

Traceback (most recent call last)"
File "manage.py", line 2, in (module)
from django.core.management import execute_manager
ImportError: cannot import name execute_manager

Both python and django are added to my system variable PATH:

...C:\Python27\;C:\Python27\Scripts\;C:\PYTHON27\DLLs\;C:\PYTHON27\LIB\;C:\Python27\Lib\site-packages\; 

I've also tried this with bash and powershell and I still get the same error.

Is this a virtualenv related issue? Django dependence issue? Yikes. How do I fix this problem? Help me Stackoverflow-kenobi your my only hope.

Kill answered 3/1, 2014 at 14:51 Comment(3)
Are you actually using virtualenv? The whole point of it is not to use the system-wide python interpreter along with its libraries. Check the accepted answer for the question: #6050433 It touches on virtualenv setup.Wheelock
@Wheelock Hmm it looks like I'm not properly running the virtualenv. After running the proper django version, I get this error: ImportError: No module named djcelery.Kill
@Wheelock I checked if django would run in python outside of my environment and it does. Also the link you suggested is for a linux environment.Kill
S
63

execute_manager deprecated in Django 1.4 as part of the project layout refactor and was removed in 1.6 per the deprecation timeline: https://docs.djangoproject.com/en/1.4/internals/deprecation/#id3

To fix this error you should either install a compatible version of Django for the project or update the manage.py to new style which does not use execute_manager: https://docs.djangoproject.com/en/stable/releases/1.4/#updated-default-project-layout-and-manage-py Most likely if your manage.py is not compatible with 1.6 then neither is the rest of the project. You should find the appropriate Django version for the project.

Sigmon answered 3/1, 2014 at 15:0 Comment(2)
Thank you for your timely reply. It looks like that helped. I'm successfully running 1.3.1 (version my project requires). However it looks like it may have been a virtualenv problem. Because I'm getting this error: ImportError: No module named djcelery.Kill
That error seems pretty clear. You haven't installed django-celery.Sigmon
K
5

@Mark Lavin explained nicely what the error means and how it arises. I think I've just discovered why others may also get this error message so leaving it here for the record.

I'm assuming you're running this from within a virtual environment.

When starting a new Django project, if you run django-admin startproject <myproject>, you are invoking the global installation of Django. If, as in my case, it comes from a stale repo, it may be an old version - in my case:

>> django-admin --version
>> 1.3.1

If you want to run Django from within a virtual environment, then you need to invoke it with django-admin.py startproject <myproject>. This way, you get a Django project with the version corresponding to your local installation:

>> django-admin.py --version
>> 1.6.6
Krys answered 2/9, 2014 at 5:50 Comment(0)
G
0

I was getting this error because I had an old version of django-admin.py in my /usr/local/bin folder and I had forgotten to create a new virtualenv for my new project.

Remember that the steps for a new project should be:

  1. First create a new virtualenv for your new project:
    mkvirtualenv <mynewproj>
  2. Update the Python version for your virtualenv if necessary:
    virtualenv --python $(which python3.6) ~/.virtualenvs/<mynewproj>
  3. Then create your Django project folder structure:
    django-admin startproject <django project name>

I also deleted my old obsolete /usr/local/bin/django-admin.py because it was created before I discovered the joys of virtualenv.

Gorgerin answered 22/3, 2018 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.