pythondjangoopenedxedxpalm

Import Errors for Custom Django Apps in XBlock Development on OpenEdX Palm Version


I’m having trouble importing custom Django apps in an Open edX XBlock. Even though the Django application is installed in the Open edX environment, I'm encountering errors.

The video_rating custom Django application is installed and working perfectly in this environment.

onlineoffline is my XBlock.

2024-07-22 10:43:36,866 WARNING 32 [xblock.plugin] [user None] [ip None] plugin.py:144 - Unable to load XBlock ‘onlineoffline’ Traceback (most recent call last): File “/openedx/venv/lib/python3.8/site-packages/xblock/plugin.py”, line 141, in load_classes yield (class_.name, cls.load_class_entry_point(class)) File “/openedx/venv/lib/python3.8/site-packages/xblock/plugin.py”, line 70, in load_class_entry_point class = entry_point.load() File “/openedx/venv/lib/python3.8/site-packages/pkg_resources/init.py”, line 2517, in load return self.resolve() File “/openedx/venv/lib/python3.8/site-packages/pkg_resources/init.py”, line 2523, in resolve module = import(self.module_name, fromlist=[‘name’], level=0) File “/openedx/venv/lib/python3.8/site-packages/onlineoffline/init.py”, line 1, in from .onlineoffline import OnlineOfflineClassXBlock File “/openedx/venv/lib/python3.8/site-packages/onlineoffline/onlineoffline.py”, line 4, in from openedx.features.video_rating.models import UserFeedbackSave,Questions,Type,Ratings ModuleNotFoundError: No module named ‘openedx.features.video_rating’


Solution

  • To resolve the issue with installing an XBlock in Open edX, follow these steps:

    1. Copy the LMS requirements folder from the container to your host server:

      tutor local copyfrom lms /openedx/requirements /home/ubuntu/Palm/volumes/requirements
      
    2. Create a docker-compose.override.yml file to override the default volumes:

      touch $TUTOR_ROOT/env/local/docker-compose.override.yml
      
    3. Add the following content to the docker-compose.override.yml file to mount the requirements folder:

      version: "3.7"
      services:
        lms:
          volumes:
            - /home/ubuntu/Palm/volumes/requirements:/openedx/requirements
        cms:
          volumes:
            - /home/ubuntu/Palm/volumes/requirements:/openedx/requirements
      
    4. Restart the Tutor environment with:

      tutor local stop
      tutor local start -d
      
    5. Create a private.txt file in the mounted requirements folder:

      /home/ubuntu/Palm/volumes/requirements/private.txt
      
    6. Add the XBlock installation details to the private.txt file:

      git+https://<git_access_token>@github.com/admin/xblock.git@<branch_name>
      
    7. Rebuild and launch the Tutor environment:

      tutor local build
      tutor local launch
      
    8. If the XBlock still isn't installed, you can manually install it inside the LMS container:

      tutor local exec lms bash
      pip install -r /openedx/requirements/private.txt
      

    These steps should help you successfully install the XBlock and resolve any related errors.