ModuleNotFoundError: No module named 'erpnext.shopping_cart.utils'

When starting a docker image with frappe v13.15.0 and erpnext v.13.15.2, I get the error below. And indeed, erpnext/shopping_cart/utils.py has been moved to ecommerce since v.13.11, see this commit. But then why is erpnext.shopping_cart.utils still referenced?

[2021-12-04 19:52:17 +0000] [18] [ERROR] Error handling request /
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 49, in render
    data = render_page_by_language(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 178, in render_page_by_language
    return render_page(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 194, in render_page
    return build(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 201, in build
    return build_page(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py", line 216, in build_page
    context = get_context(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/context.py", line 28, in get_context
    context = build_context(context)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/context.py", line 134, in build_context
    values = frappe.get_attr(method)(context)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1199, in get_attr
    return getattr(get_module(modulename), methodname)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 975, in get_module
    return importlib.import_module(modulename)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'erpnext.shopping_cart.utils'

These are the only rows in the DB related to shopping_cart

('49c53466ce','2015-08-07 02:33:52.670866','2021-07-20 07:29:43.586529','Administrator','Administrator',0,'Tax Rule','fields','DocType',2,'use_for_shopping_cart','Use for Shopping Cart',NULL,'Check',NULL,NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0,NULL,NULL,NULL,NULL,NULL,0,0,NULL,NULL,0,'1',NULL,0,0,0,0,0,0,0,0,0,0,NULL,0,0,0,0,0,NULL,0),
('853b2cca8e','2013-03-07 11:42:57.000000','2021-09-28 14:28:48.877285','Administrator','Administrator',0,'Quotation Item','fields','DocType',67,'shopping_cart_section','Shopping Cart',NULL,'Section Break',NULL,NULL,0,0,0,0,0,0,0,0,0,1,0,0,0,0,NULL,NULL,NULL,NULL,NULL,0,0,NULL,NULL,0,NULL,NULL,0,0,0,0,0,0,0,0,0,0,NULL,0,0,0,0,0,NULL,0),
('cb834795d5','2013-03-07 11:42:58.000000','2021-04-29 09:02:41.458766','Administrator','Administrator',0,'Sales Order Item','fields','DocType',79,'shopping_cart_section','Shopping Cart',NULL,'Section Break',NULL,NULL,0,0,0,0,0,0,0,0,0,1,0,0,0,0,NULL,NULL,NULL,NULL,NULL,0,0,NULL,NULL,0,NULL,NULL,0,0,0,0,0,0,0,0,0,0,NULL,0,0,0,0,0,NULL,0),
('PATCHLOG00065','2020-12-05 23:49:35.877510','2020-12-05 23:49:35.877510','Administrator','Administrator',0,NULL,NULL,NULL,0,'frappe.patches.v5_0.remove_shopping_cart_app',NULL,NULL,NULL,NULL),
('PATCHLOG01165','2021-10-08 06:17:41.528459','2021-10-08 06:17:41.528459','Administrator','Administrator',0,NULL,NULL,NULL,0,'erpnext.patches.v13_0.shopping_cart_to_ecommerce',NULL,NULL,NULL,NULL),
  `use_for_shopping_cart` int(1) NOT NULL DEFAULT 1,

… and removing them does not solve the problem.

EDIT: when using the containers tagged with ‘latest’, I get another shopping_cart related problem:

[2021-12-05 10:55:15 +0000] [21] [ERROR] Error handling request /
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py", line 205, in load_doctype_module
    doctype_python_modules[key] = frappe.get_module(module_name)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 903, in get_module
    return importlib.import_module(modulename)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'frappe.core.doctype.shopping_cart_settings'

I’m able to create erpnext site using following .env

LETSENCRYPT_EMAIL=email@example.com
ERPNEXT_VERSION=v13.15.2
FRAPPE_VERSION=v13.15.0
MARIADB_HOST=mariadb
MYSQL_ROOT_PASSWORD=admin
SITE_NAME=mysite.localhost
SITES=`mysite.localhost`
DB_ROOT_USER=root
ADMIN_PASSWORD=admin
INSTALL_APPS=erpnext
ENTRYPOINT_LABEL=traefik.http.routers.erpnext-nginx.entrypoints=web
CERT_RESOLVER_LABEL=erpnext.local.no-cert-resolver
HTTPS_REDIRECT_RULE_LABEL=erpnext.local.no-redirect-rule
HTTPS_REDIRECT_ENTRYPOINT_LABEL=erpnext.local.no-entrypoint
HTTPS_REDIRECT_MIDDLEWARE_LABEL=erpnext.local.no-middleware
HTTPS_USE_REDIRECT_MIDDLEWARE_LABEL=erpnext.local-no-redirect-middleware
SKIP_NGINX_TEMPLATE_GENERATION=0
WORKER_CLASS=gevent

Are you trying to upgrade? Did you migrate?

Can you try recreating containers?

Do not use latest tag. They are the develop/edge images.

Thanks for your answer. I am trying to move an existing installation to a docker installation with the same frappe and erpnext versions. Hence I think I do not need to migrate.

I tried your .env, except from

SITES=`mysite.localhost`

which gives

mysite.localhost: command not found

I recreated the containers. Same error.
I also tried with empty tars for the file and a database with no data (just the schema). Then, there is another exception, but in the course of handling it, again the shopping_cart related exception is thrown.

Is there a way to create a fresh (i.e. minimal working) database (for testing)?

EDIT: with v13.10.0 for both frappe and erpnext, the error does not occur.

Hi @tillmo

I too faced the same problem.
Try the below command

bench build

Checkout this thread for more help

Hi @nasir,
many thanks for the hint. My problem is that I use the official ERPNext docker images, and they do not have bench installed. One has to create a new image with bench installed. Do you know if such images already exist somewhere? Or is there a script to install bench on top of an existing image?
Best, Till

Unfortunately, I don’t have much idea about docker. Revant_one is the docker king here. Perhaps he can guide you.

Had the same issue and could solve it, by bashing into the python container and running migrate:

docker-compose --project-name crm exec erpnext-python "bash"
# now go into the site folder (replace {YOUR_SITENAME} with your sitename folder name
cd {YOUR_SITENAME}
# Then you can call bench commands
bench --site={YOUR_SITENAME} migrate
# now disable maintenance mode again
bench --site={YOUR_SITENAME} set-maintenance-mode=off

Hope that helps anyone in the future.

1 Like