3.2. Set Up the XBlock Software Development Kit#

Before you continue, make sure that you are familiar with the subjects in the Install XBlock Prerequisites section.

When you have installed all prerequisites, you are ready to set up the XBlock SDK in a virtual environment. To do this, complete the following steps.

3.2.1. Create a Directory for XBlock Work#

It is recommended that you create a directory in which to store all your XBlock work, including a virtual environment, the XBlock SDK, and the XBlocks you develop.

  1. At the command prompt, run the following command to create the directory.

    $ mkdir xblock_development
  2. Change directories to the xblock_development directory.

    $ cd xblock_development

    The rest of your work will be from this directory.

3.2.2. Create and Activate the Virtual Environment#

You must have a virtual environment tool installed on your computer. For more information, see Install XBlock Prerequisites.

Then create the virtual environment in your xblock_development directory.

  1. At the command prompt in xblock_development, run the following command to create the virtual environment.

    $ virtualenv venv
  2. Run the following command to activate the virtual environment.

    $ source venv/bin/activate

    When the virtual environment is activated, the command prompt shows the name of the virtual directory in parentheses.

    (venv) $

3.2.3. Clone the XBlock Software Development Kit#

The XBlock SDK is a Python application you use to help you build new XBlocks. The XBlock SDK contains three main components:

  • An XBlock creation tool that builds the skeleton of a new XBlock.

  • An XBlock runtime for viewing and testing your XBlocks during development.

  • Sample XBlocks that you can use as the starting point for new XBlocks, and for your own learning.

After you create and activate the virtual environment, you clone the XBlock SDK and install its requirements. To do this, complete the following steps at a command prompt.

  1. In the xblock_development directory, run the following command to clone the XBlock SDK repository from GitHub.

    (venv) $ git clone https://github.com/openedx/xblock-sdk.git
  2. In the same directory, create an empty directory called var.

    (venv) $ mkdir var
  3. Run the following command to change to the xblock-sdk directory.

    (venv) $ cd xblock-sdk
  4. Run the following commands to install the XBlock SDK requirements.

    (venv) $ make install
  5. Run the following command to return to the xblock_development directory, where you will perform the rest of your work.

    (venv) $ cd ..

When the requirements are installed, you are in the xblock_development directory, which contains the venv and xblock-sdk subdirectories. You can now create your first XBlock.