I'm building a django oscar commerce v 3.2 project(https://github.com/django-oscar/django-oscar) on ubuntu 20.04 on GCP with a virtual environment using python 3.8.14 and getting the following error when i run the docker build command using
docker-compose -f docker-compose-full.yml up
ModuleNotFoundError: No module named 'sandbox'
The trace is with regards to the following line in my settings.py:
from sandbox.environment import EnvironmentChecker
My project folder structure is as follows :
django-commerce
|- src
|- sandbox
| |- __init__.py
| |- environment.py
| |- settings.py
| |- manage.py
| |- urls.py
| |- wsgi.py
| |- uwsgi.ini
|- DockerFile
|- MakeFile
|- Manifest.in
|- setup.py
|- setup.cfg
The top lines in my Settings.py
import os
import sys
import logging.config
from django.utils.translation import gettext_lazy as _
from sandbox.environment import EnvironmentChecker
Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Path helper
location = lambda x: os.path.join(
os.path.dirname(os.path.realpath(__file__)), x)
My wsgi.py
# isort:skip
import os
import sys
root_path = os.path.abspath(os.path.split(__file__)[0])
sys.path.insert(0, os.path.join(root_path, 'django-commerce'))
sys.path.insert(0, root_path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.wsgi import get_wsgi_application # isort:skip
application = get_wsgi_application()
I've also tried adding django-commerce.sandbox to my INSTALLED_APPS in settings.py as a last try but its not working. I've spent hours trying this to work. Help appreciated.
My docker make file :
VENV = venv
PYTEST = $(PWD)/$(VENV)/bin/py.test
# These targets are not files
.PHONY: build_sandbox clean compile_translations coverage css docs extract_translations help install install-python \
install-test install-js lint release retest sandbox_clean sandbox_image sandbox test todo venv
help: ## Display this help message
@echo "Please use \`make <target>\` where <target> is one of"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; \
{printf "\033[36m%-40s\033[0m %s\n", $$1, $$2}'
##################
# Install commands
##################
install: install-python install-test assets ## Install requirements for local development and production
install-python: ## Install python requirements
pip install -r requirements.txt
install-test: ## Install test requirements
pip install -e .[test]
install-migrations-testing-requirements: ## Install migrations testing requirements
pip install -r requirements_migrations.txt
assets: ## Install static assets
npm install
npm run build
# venv: ## Create a virtual env and install test and production requirements
# $(shell which python3) -m venv $(VENV)
# $(VENV)/bin/pip install -e .[test]
# $(VENV)/bin/pip install -r docs/requirements.txt
#############################
# Sandbox management commands
#############################
sandbox: install build_sandbox ## Install requirements and create a sandbox
build_sandbox: sandbox_clean sandbox_load_user sandbox_load_data ## Creates a sandbox from scratch
sandbox_clean: ## Clean sandbox images,cache,static and database
# Remove media
-rm -rf sandbox/public/media/images
-rm -rf sandbox/public/media/cache
-rm -rf sandbox/public/static
-rm -f sandbox/db.mysql
# Create database
python3.8 sandbox/manage.py migrate
sandbox_load_user: ## Load user data into sandbox
python3.8 sandbox/manage.py loaddata sandbox/fixtures/auth.json
sandbox_load_data: ## Import fixtures and collect static
# Import some fixtures. Order is important as JSON fixtures include primary keys
python3.8 sandbox/manage.py loaddata sandbox/fixtures/child_products.json
python3.8 sandbox/manage.py commerce_import_catalogue sandbox/fixtures/*.csv
python3.8 sandbox/manage.py commerce_import_catalogue_images sandbox/fixtures/images.tar.gz
python3.8 sandbox/manage.py commerce_populate_countries --initial-only
python3.8 sandbox/manage.py loaddata sandbox/fixtures/pages.json sandbox/fixtures/ranges.json sandbox/fixtures/offers.json
python3.8 sandbox/manage.py loaddata sandbox/fixtures/orders.json
python3.8 sandbox/manage.py clear_index --noinput
python3.8 sandbox/manage.py update_index catalogue
python3.8 sandbox/manage.py thumbnail cleanup
python3.8 sandbox/manage.py collectstatic --noinput
sandbox_image: ## Build latest docker image of django-commerce-sandbox
docker build -t django-commerce-sandbox:latest .
##################
# Tests and checks
##################
test: venv ## Run tests
$(PYTEST)
retest: venv ## Run failed tests only
$(PYTEST) --lf
coverage: venv ## Generate coverage report
$(PYTEST) --cov=commerce --cov-report=term-missing
lint: ## Run flake8 and isort checks
flake8 src/commerce/
flake8 tests/
isort -c -q --diff src/ tests/
test_migrations: install-migrations-testing-requirements ## Tests migrations
cd sandbox && ./test_migrations.sh
#######################
# Translations Handling
#######################
extract_translations: ## Extract strings and create source .po files
cd src/commerce; django-admin.py makemessages -a
compile_translations: ## Compile translation files and create .mo files
cd src/commerce; django-admin.py compilemessages
######################
# Project Management
######################
clean: ## Remove files not in source control
find . -type f -name "*.pyc" -delete
rm -rf nosetests.xml coverage.xml htmlcov *.egg-info *.pdf dist violations.txt
docs: venv ## Compile docs
make -C docs html SPHINXBUILD=$(PWD)/$(VENV)/bin/sphinx-build
todo: ## Look for areas of the code that need updating when some event has taken place (like Commerce dropping support for a Django version)
-grep -rnH TODO *.txt
-grep -rnH TODO src/commerce/apps/
-grep -rnH "django.VERSION" src/commerce/apps
release: clean ## Creates release
pip install twine wheel
rm -rf dist/*
rm -rf src/commerce/static/*
npm run build
python setup.py sdist bdist_wheel
twine upload -s dist/*
The docker build stops above at sandbox_clean in the Make file with the trace of
File "/app/sandbox/settings.py", line 5, in <module>
from sandbox.environment import EnvironmentChecker
ModuleNotFoundError: No module named 'sandbox'
make: *** [Makefile:50: sandbox_clean] Error 1