Skip to main content
This doc relates to the below revision of hardware
Mecha Logo

Comet (rev5)

For Pilot users

The all new Mecha Comet

Better in all ways, the next revision of Mecha Comet, coming soon.

Setting up pyenv

This guide will help you set up pyenv on your Mecha Comet. We are told that Python developers love it 😍.

pyenv is a lightweight, flexible tool for managing multiple Python versions. It lets you -

  • Easily switch between Python versions
  • Create and manage isolated Python environments for different projects
  • Avoid conflicts between system Python and custom-installed Python versions

Installing pyenv

1

List all available python versions using the command below.

$ sudo apt update
$ sudo apt curl git
2

Run the below command to install pyenv

$ curl https://pyenv.run | bash
3

Now lets configure the default shell to include pyenv in the PATH. Add the following lines to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc):

# Assuming your shell is bash
$ nano ~/.bashrc

Add the following lines at the end of the file.

# ~/.bashrc
...
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
4

Restart your shell for the changes to take effect -

$ exec "$SHELL"
5

To confirm that pyenv is installed correctly, run the below command.

$ pyenv --version

Setting up a project to test pyenv

Follow the quick guide below to test pyenv by setting up a test project at a certain python version.

1

List all available Python versions using the command below and lets install a specific version, for example 3.11.0.

$ pyenv install --list
$ pyenv install 3.11.0
2

Create a project directory and set Python version for the project.

$ mkdir my_project
$ cd my_project
3

Now to create a virtual environment for your project

$ pyenv virtualenv 3.11.0 my_env

To activate the environment`

$ pyenv activate my_env

You should see the command prompt change to reflect the environment name my_env. You are now all set!

tip

In a new terminal when you resume your work, you will only need to run the above command that activates the virtual environment.

4

Now lets confirm if python is running at this version in the virtual environment.

In the same folder, create a new main.py

$ nano main.py

Add the following code that prints the python version.

import sys
print(sys.version)

Now lets run this program, while in an activate virtual environment`

$ python main.py
3.11.0 (main, Feb 16, 18:14:09) [GCC 11.4.0]

You have successfully configured and tested pyenv and virtualenv now!

Some useful commands

Here are some common commands that you will need at some point when using pyenv.

List all available Python versions

$ pyenv install --list

Install a specific Python version

$ pyenv install 3.11.4

Set a global Python version

$ pyenv global 3.11.4

Set a local Python version for a project

$ pyenv local 3.10.8

View the current Python version

$ pyenv version

List all versions installed

$ pyenv versions