Skip to content

Setting up a virtualenv for blockly

RaghuvirShirodkar edited this page Nov 14, 2023 · 1 revision

The problem:

In a nutshell: blockly needs python2.7.

Since an installation of python3+ is necessary for the lab and cross compilers, it can't be used directly with blockly.

The solution:

Setting up virtualenv

The easiest way is to install a virtualenv. Open the blockly project and follow these steps:

  • Install the python plugin für IntelliJ in File -> Settings -> Plugins:
    • Shortcut: Ctrl + Alt + S

Installing python plugin

  • Setup the project structure in File -> Project Structure -> Project Settings -> Project:
    • Shortcut: Ctrl + Alt + Shift + S

Setting up project structure

  • Add a new SDK, in case one is not available:

Adding SDK

  • In Add Python Interpreter window, select the following options:
    • Virtualenv Environment
    • Base interpreter: /usr/bin/python2.7
      • Simply copy the above mentioned location and paste it into Base interpreter, instead of searching for it!

Adding python interpreter

  • And that's it! IntelliJ will download virtualenv in the background. To test the installation, open a Terminal window:

    • Shortcut: Alt + F12

    Opening Terminal

    • In an open Terminal window, click on +

    Opening Terminal window

  • When everything was setup correctly, (venv) will show up at the start of the command:

    • With python --version the version of python being used can be checked
    • With which python the source of python can be verified

    Checking python version

    • With deactivate the virtualenv can be deactivated

    Deactivating virtualenv

    • And by opening a new Terminal window the virtualenv is activated again

    Opening a new Terminal window Activating virtualenv

Adding run configuration

Now a run configuration can be added to further ease building blockly. Following are the steps for the same:

  • Click on Run -> Edit configurations or as follows:

Editing configurations

  • Add a new run configuration by clicking on Add new run configuration:

Adding new configuration

  • Select Python from the dropdown:

Selecting python

  • Enter the following particulars in the next window:
    • Name: Build
    • script: build.py

Setting up configuration

  • Click on Apply and OK and that's it! Now the created run configuration will show up as follows:

Created run configuration

By clicking on GetImage (4) the configuration will be run, which in turn generates the blockly resources (compressed and messages).

Clone this wiki locally