Skip to content

Configuring Intellij to use Python and deploy to the Raspberry Pi

Gary Rowe edited this page Feb 1, 2014 · 5 revisions

Intellij Ultimate is my IDE of choice and it is very versatile. One useful feature is the Python plugin which enables Intellij to process Python projects and provide rapid deployment to a remote server for execution and remote debugging.

Here's how to get it set up.

Ensure the RPi is configured for running the emulator

Use these instructions to get your RPi ready for Trezor emulation.

Install Python on your machine

Most systems will have Python already, but if not just visit the main Python site and follow their instructions.

We recommend you install pip and virtualenv to simplify the process of creating Python projects that have isolated dependencies in a similar manner to Maven in Java.

Add the Python plugin to Intellij

Install the Python plugin into Intellij using the standard method. Use Settings | Plugins | Browse repositories | "Python".

Clone the Trezor emulator repo

The Trezor Emulator repository provides a fully operational Trezor emulator written in Python.

  • Clone the repo as normal (VCS | Checkout from version control | Git) from master

Attempt to run the emulator outside of the IDE in virtualenv

If you are running Debian/Ubuntu/Raspbian you will be able to run the Trezor Emulator on your desktop. If not then the following will fail due to the spidev-2.0 library requiring Linux.

$ cd trezor-emu
$ virtualenv env
$ source env/bin/activate
(env) $ pip install protobuf ecdsa
(env) $ sudo python setup.py develop
(env) $ ./emu.sh

If you wish to leave virtualenv use

(env) $ deactivate
$

Add Python SDK to the project

  • Select project settings
  • Select Platform Setting | SDKs | Add New SDK | Python SDK
  • Select local Python 2.7.1+ (or choose a virtualenv if you prefer)
  • Wait for configuration to complete

Configure remote deployment to the RPi

  • Within project settings | Modules, select "Remote...."
  • Fill in the RPi IP address, username ("pi") and password ("raspberry")
  • Click "Test connection" shows "Successfully connected"
  • Click "OK"
  • Wait for Intellij to complete uploading helper libraries to RPi via SFTP

Add RPi to the Deployment list

  • Select Settings | Deployment
  • Add deployment "Trezor"
  • SFTP host: 192.168.0.1 (or whatever the IP address of the RPi is)
  • Port: 22
  • Root path: /home/pi
  • User name: pi
  • Auth type: Password
  • Password: raspberry (or whatever you've changed it to)
  • Save password: Ticked
  • Click Test SFTP Connect to verify

Add key bindings to speed up uploads

  • Use Settings | Keymap to bind CTRL+U to "Deployment upload"

Now each time you make a change to a local Python file, clicking CTRL+U will trigger the upload process that will log in to the RPi, SFTP the file to the appropriate location (e.g. ~/trezor-emu/rpi-serial.sh) saving you a lot of time with keeping the remote and local in sync.

Test it out

Try making a change to a file, say adding a print "Hello" to the /trezor/__init__.py file main method (observing the same indentation). Use CTRL + U, then SSH to the RPi and run the sudo ./rpi-serial.sh script. If you're careful you'll see your new message appear. Try flipping back and forth between your Intellij environment and the RPi and you'll see near instant updates on restarting the script.