首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:模块'profile‘没有属性'run’

AttributeError:模块'profile‘没有属性'run’
EN

Stack Overflow用户
提问于 2019-08-02 17:41:20
回答 2查看 2.8K关注 0票数 5

所以我有一个扩展的用户模型(扩展的AbstractUser)叫做Profile。这是一个单独的名为“配置文件”的应用程序。我插入了标准登录,并意识到它正在寻找一个“配置文件”应用程序名称作为标准,所以我重新命名它(目录,代码,数据库模式),我认为应该可以工作。在apps.py中,app_name实际上已经被设置为"profile“,所以不需要重命名url引用。

没有骰子。我得到了标题中的错误。

因此,我删除了所有迁移(我现在仍然可以这样做OK :),并删除了我当前正在使用的sqlite DB,认为我应该重新运行迁移并重新创建所有内容。

同样的错误。

堆栈跟踪为:

代码语言:javascript
复制
λ  python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 361, in execute
    self.check()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\apps.py", line 18, in check_middleware
    from debug_toolbar.middleware import DebugToolbarMiddleware
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\middleware.py", line 12, in <module>
    from debug_toolbar.toolbar import DebugToolbar
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 141, in <module>
    urlpatterns = DebugToolbar.get_urls()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 134, in get_urls
    for panel_class in cls.get_panel_classes():
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 116, in get_panel_classes
    import_string(panel_path) for panel_path in dt_settings.get_panels()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 116, in <listcomp>
    import_string(panel_path) for panel_path in dt_settings.get_panels()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\panels\profiling.py", line 1, in <module>
    import cProfile
  File "D:\Python\Python37-32\Lib\cProfile.py", line 22, in <module>
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'

作为重命名的一部分,我遗漏了什么?

有没有其他我错过的信息会有帮助呢?(我已经搜索了“profile”的任何实例,但现在所有内容都被正确地重命名了,并且在此之前应用程序工作正常,所以纯粹是这个重命名搞乱了它)。

编辑:会不会是"profile“与一些内部python例程冲突?python安装下的cProfile.py文件定义为

代码语言:javascript
复制
#! /usr/bin/env python3

"""Python interface for the 'lsprof' profiler.
   Compatible with the 'profile' module.
"""

这跟我的项目没什么关系吧?我是否只需要将我的应用程序/扩展用户模型称为"profile“以外的其他名称?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-02 19:26:59

好的。所以,是的,这是一个命名冲突。我已经将我的"Profile“模型和"profile”应用程序重命名为"UserProfile“和"user_profile”,并相应地更新了所有内容。现在这一切似乎都起作用了。

只是在这里写一个答案,以防将来有任何人遇到同样的问题!

票数 14
EN

Stack Overflow用户

发布于 2020-12-29 19:20:53

在我的例子中,它是profile.py文件。

请删除该文件,然后重试。

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57323834

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档