Python 导入错误无法在windows环境中导入名称execute_manager

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20906305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:30:26  来源:igfitidea点击:

Import error cannot import name execute_manager in windows environment

pythondjangovirtualenvvirtualenvwrapper

提问by Modelesq

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)

我会让你加快速度。我正在尝试设置 Windows 开发环境。我已经成功安装了 python、django 和 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 runserverfrom my cloned repository I get this error:

但是当我运行:python manage.py runserver从我克隆的存储库时,我收到此错误:

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:

python和django都添加到我的系统变量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.

我也用 bash 和 powershell 尝试过这个,但我仍然遇到同样的错误。

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

这是一个与 virtualenv 相关的问题吗?Django依赖问题?哎呀。我该如何解决这个问题?帮助我 Stackoverflow-kenobi 你是我唯一的希望。

采纳答案by Mark Lavin

execute_managerdeprecated 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

execute_manager作为项目布局重构的一部分,在 Django 1.4 中已弃用,并在 1.6 中根据弃用时间表删除: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.pyto new style which does not use execute_manager: https://docs.djangoproject.com/en/stable/releases/1.4/#updated-default-project-layout-and-manage-pyMost likely if your manage.pyis not compatible with 1.6 then neither is the rest of the project. You should find the appropriate Django version for the project.

要修复此错误,您应该为项目安装兼容版本的 Django 或将manage.py不使用的新样式更新为execute_managerhttps: //docs.djangoproject.com/en/stable/releases/1.4/#updated-default- project-layout-and-manage-py最有可能的manage.py是,如果您与 1.6 不兼容,那么项目的其余部分也不兼容。您应该为该项目找到合适的 Django 版本。

回答by Gabriel

@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.

@Mark Lavin 很好地解释了错误的含义以及它是如何产生的。我想我刚刚发现为什么其他人也可能会收到此错误消息,因此将其留在这里以作记录。

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 项目时,如果你运行django-admin startproject <myproject>,你正在调用 Django 的全局安装。如果,就像我的情况一样,它来自一个陈旧的回购,它可能是一个旧版本 - 在我的情况下:

>> 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 localinstallation:

如果要在虚拟环境中运行 Django,则需要使用django-admin.py startproject <myproject>. 这样,您将获得一个版本与您本地安装对应的 Django 项目:

>> django-admin.py --version
>> 1.6.6

回答by Brendan Quinn

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

我收到这个错误是因为我的文件夹中有一个旧版本,django-admin.py/usr/local/bin忘记为我的新项目创建一个新的 virtualenv。

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>
  1. 首先为你的新项目创建一个新的 virtualenv:
    mkvirtualenv <mynewproj>
  2. 如有必要,更新您的 virtualenv 的 Python 版本:
    virtualenv --python $(which python3.6) ~/.virtualenvs/<mynewproj>
  3. 然后创建您的 Django 项目文件夹结构:
    django-admin startproject <django project name>

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

我还删除了我的旧过时,/usr/local/bin/django-admin.py因为它是在我发现virtualenv.