RustPython Blog
Using RustPython with PyCharm and Visual Studio Code on macOS.
Create an issue if you see something wrong. Edit posts or create new ones via PR on github.com/RustPython/rustpython.github.io

For macOS, here is how you can setup RustPython as an interpreter for PyCharm and Visual Studio Code.

Pre-requisites

You will need:

Here are the commands to install them:

  • xcode-select --install
  • curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

(those might change over time)

Install RustPython

First run:

cargo install --git https://github.com/RustPython/RustPython

If you want RustPython with ssl support, try:

cargo install --git https://github.com/RustPython/RustPython --features ssl

Go to Cargo’s bin directory with cd ~/.cargo/bin. Run ls, you should see the binary ~/.cargo/bin/rustpython.

If you type rustpython at the terminal, you should get the welcome message:
RustPython Welcome Message

Setup PyCharm

In PyCharm, you can add an interpreter by using:

  • virtual environment
  • conda
  • pipenv
  • system interpreter
  • poetry

The full docs are on this link. This blog post is for the two options: virtual environment and system interpreter.

System interpreter

Go to “Add Python Interpreter” -> System Interpreter -> Click on the browse icon.

PyCharm add Interpreter

Navigate to /Users/YOURUSERNAME/.cargo/bin - selecting rustpython as the interpreter gives this error:

PyCharm add Interpreter

There is an easy fix. Create a link/shortcut called python that points to rustpython.

cd ~/.cargo/bin
ln -s rustpython python

PyCharm is happy. Test out that things work by creating a python file in PyCharm and running

import sys
print(sys.executable)

Virtual environment

In the screen above, if you try to use the virtual option, you get this error.

venv error

However, you can still manually create the virtual environment. First, create a directory, cd into into it and run: ~/.cargo/bin/rustpython -m venv env --without-pip

This would create a virtual environement that looks like this.

venv

Go the directory, open PyCharm, now you can set the interpreter from the virtual environement.

Setup Visual Studio Code

Install the Python Extension by Micorsoft. Create your Python file and press Command + Shift + P, then search for “Python: Select Interpreter”, add a new interpreter by using “Enter Interpreter Path” then browse your filesystem, go to ~/.cargo/bin/rustpython

You can repeat the same steps for creating a virtual environement and using that with Visual Studio Code.