V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
paicha
V2EX  ›  Python

python manage.py runserver 报错

  •  
  •   paicha ·
    paicha · 2013-05-13 18:02:05 +08:00 · 6557 次点击
    这是一个创建于 4010 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我在搭建 Python + Django 的 WEB 服务器

    Python 现在安装了两个版本:

    Python2.72(编译安装的)

    Python2.43(网上看到说如果卸载这个版本会出现很多问题,所以就不敢卸载了)

    ======================================================
    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

    不过执行 python2 manage.py runserver 是可以运行成功的。

    但是用 Python2 命令的话,发现是 Python2.43 版本,有些功能实现不了。

    所以需要在 Python2.72 下运行,但是一直报错,求搭救。
    13 条回复    1970-01-01 08:00:00 +08:00
    SErHo
        1
    SErHo  
       2013-05-13 18:16:25 +08:00
    估计是django没有在2.72的PATH里面,你试一下import django 有没有问题。
    chemzqm
        2
    chemzqm  
       2013-05-13 18:28:28 +08:00
    好奇你在用什么系统,怎么默认python版本是2.4.3
    paicha
        3
    paicha  
    OP
       2013-05-13 18:29:20 +08:00
    @SErHo

    是用这样的命令吗?初学勿怪

    Python 2.7.2 (default, May 11 2013, 23:47:25)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> print django
    <module 'django' from '/usr/local/lib/python2.7/site-packages/django/__init__.pyc'>
    >>>
    paicha
        4
    paicha  
    OP
       2013-05-13 18:30:40 +08:00
    @chemzqm CentOS 5.8 空间商安装的。
    notedit
        5
    notedit  
       2013-05-13 18:45:21 +08:00
    不是import execute_manager 的错误 是你的程序在import 其他的模块的时候已经已经报错了 但是被django 给统一扑捉了 所以报import execute_manager的错误
    paicha
        6
    paicha  
    OP
       2013-05-13 19:25:29 +08:00 via Android
    @notedit 虽然不太懂,但是要怎么解决?
    notedit
        7
    notedit  
       2013-05-13 20:03:31 +08:00
    在manager.py 中 ImportError 下面 添加:

    import traceback
    traceback.print_exc()

    你就知道错误了
    paicha
        8
    paicha  
    OP
       2013-05-13 20:17:22 +08:00
    @notedit

    一下是修改后的 manager.py

    #!/usr/bin/env python
    from django.core.management import execute_manager
    import imp
    try:
    imp.find_module('settings') # Assumed to be in the same directory.
    except ImportError:

    import traceback #增加的代码
    traceback.print_exc()

    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
    sys.exit(1)

    import settings

    if __name__ == "__main__":
    execute_manager(settings)

    =======运行===================
    [root@server test]# python manage.py runserver 0.0.0.0:8000
    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

    =============================================

    还是一样的错误提示。
    DH
        9
    DH  
       2013-05-13 20:23:48 +08:00   ❤️ 1
    就是路径的问题。一般用django的话,

    用virtualenv 配环境的,在家 pip 安装需要的 包。这基本上是标准流程。
    你试着重新配一次环境(标准,流程很重要,这也是要学习的,而不光是代码本身)。

    安装
    * python
    * pip
    * virtualenv

    然后到你的网站目录:
    virtualenv --distribute venv
    source venv/bin/activate
    pip install -r requirements.txt

    (完了要检查一下package有没有安装到 venv/lib/python2.x 下面)
    如果你用的centos,可能要先 sudo -s


    requirements.txt一般这么写

    Django==1.5.0
    PIL==1.1.7
    django-redis==3.1.7
    psycopg2==2.4.6
    paicha
        10
    paicha  
    OP
       2013-05-13 20:24:45 +08:00
    @notedit 不知道是不是这样做,只会一些基本的命令。

    当初就想自己有服务器就别浪费,如果实在搞不定,就在 SAE 里搭建好了。

    捂脸。。。(话说,V2EX不能贴图,也没一些简单的表情呢,简洁得有点不习惯)
    paicha
        11
    paicha  
    OP
       2013-05-13 20:26:53 +08:00
    @DH 好的,谢谢,我再折腾看看。
    notedit
        12
    notedit  
       2013-05-14 08:38:35 +08:00
    仔细看了一下 是路径问题 你要用python2.7 要在python2.7下安装django
    paicha
        13
    paicha  
    OP
       2013-05-14 12:30:08 +08:00
    @notedit 好的,那我重新安装一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   739 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 21:03 · PVG 05:03 · LAX 14:03 · JFK 17:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.