AttributeError: module 'profile' has no attribute 'run'

Question:

So I have an extended User model (extended AbstractUser) called Profile. This was in a seperate app called “profiles”. I was plugging in the standard login and realised it was looking for a “profile” app name as standard, so I renamed it (directories, code, DB schema) which I thought should work. app_name was actually already set to “profile” in apps.py, so didn’t need to rename url references.

No dice. I get the error in the title.

So I removed all migrations (I’m at the stage where I can still do this OK 🙂 ) and deleted the sqlite DB that I’m currently working with, thinking I’d just rerun the migrations and recreate everything.

Same error.

The stack trace is:

λ  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:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocoremanagement__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocoremanagement__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocoremanagementbase.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocoremanagementbase.py", line 361, in execute
    self.check()
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocoremanagementbase.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocoremanagementbase.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangocorechecksregistry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbarapps.py", line 18, in check_middleware
    from debug_toolbar.middleware import DebugToolbarMiddleware
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbarmiddleware.py", line 12, in <module>
    from debug_toolbar.toolbar import DebugToolbar
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbartoolbar.py", line 141, in <module>
    urlpatterns = DebugToolbar.get_urls()
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbartoolbar.py", line 134, in get_urls
    for panel_class in cls.get_panel_classes():
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbartoolbar.py", line 116, in get_panel_classes
    import_string(panel_path) for panel_path in dt_settings.get_panels()
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbartoolbar.py", line 116, in <listcomp>
    import_string(panel_path) for panel_path in dt_settings.get_panels()
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdjangoutilsmodule_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibimportlib__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:Usersmjnic.virtualenvspyp-E_0Se9Bllibsite-packagesdebug_toolbarpanelsprofiling.py", line 1, in <module>
    import cProfile
  File "D:PythonPython37-32LibcProfile.py", line 22, in <module>
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'

What have I missed as part of this rename?

Any other info I’ve missed posting that would help? (I’ve searched for any instance of “profiles”, but everything is correctly renamed now, and the app was working OK prior to this, so it’s purely this rename that’s messed it up).

Edit: Can it be that “profile” conflicts with some internal python routine? That cProfile.py file under the python installation is defined as

#! /usr/bin/env python3

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

Now that can’t be anything to do with my project? Do I just need to call my app/extended user model something other than “profile”?

Asked By: michjnich

||

Answers:

OK. So yes, it’s a naming clash. I’ve renamed my “Profile” model and “profile” app as “UserProfile” and “user_profile” and updated everything accordingly. It all seems to work now …

Just putting an answer here in case anybody comes along in the future with the same issue!

Answered By: michjnich

In my case, it was profile.py file.

Delete the file and try again.

Answered By: Rohit Swami

In my case was the conflict between app – ‘profile’ and ‘django-debug-toolbar’:

I rename my app from ‘profile’ to ‘account’ and it solved the problem

Answered By: alexey