NavigationContentFooter
Jump toSuggest an edit

How to use Pipenv to create virtual environments on Scaleway GPU Instances

Reviewed on 17 July 2024Published on 25 March 2022

Pipenv is a powerful package and dependency manager for Python projects. It combines the functionalities of several tools:

  • pip for managing Python packages
  • pyenv for managing Python versions
  • Virtualenv for creating isolated Python environments
  • Pipfile for managing project dependencies

Pipenv is preinstalled on all Scaleway AI Docker images for GPU Instances. When you launch one of these Docker images, you are placed in an activated Pipenv virtual environment with preinstalled packages and tools. You can also create your own virtual environments using Pipenv.

Before you start

To complete the actions presented below, you must have:

Requirements

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • A GPU Instance
  • An SSH key added to your account

Accessing the preinstalled Pipenv virtual environment

Refer to our dedicated documentation on how to access the Pipenv virtual environment from your Scaleway GPU Instance.

Managing packages with Pipenv

You can view, install, uninstall, and update packages using simple pipenv commands:

  1. View installed packages and dependencies:

    pipenv graph
  2. Install a new package:

    pipenv install <package>
    Tip

    To install a specific version of a package, use the command pipenv install <package>~=1.2.

  3. Uninstall a package:

    pipenv uninstall <package>
  4. Update a package:

    pipenv update <package>
    Tip

    To update all packages, simply run pipenv update.

    Important

    Be aware that installing and updating packages may cause conflicts with the existing virtual environment installation.

Understanding Pipfiles

Each Pipenv virtual environment has a Pipfile that details project dependencies, replacing the typical requirements.txt file. When you create a Pipenv environment, a Pipfile is automatically generated.

  1. View Pipfile contents:

    cat Pipfile

    The Pipfile includes:

    • source: Package sources
    • packages: Required packages for production and development
    • dev-packages: Required packages for development only
    • requires: Required Python version

    Packages installed with pipenv install <package> are added to the Pipfile. This allows others to install dependencies from the Pipfile with pipenv install.

  2. View Pipfile.lock contents:

    cat Pipfile.lock

    The Pipfile.lock specifies package versions to prevent breaking changes from dependency upgrades.

Creating your own virtual environments

  1. Connect to your GPU Instance via SSH and launch a Scaleway AI Docker container.

    You will be in the ~/ai directory with the virtual environment activated.

  2. Exit the current virtual environment:

    exit
  3. Navigate to the home directory:

    cd ~
  4. Create a new project directory and navigate into it:

    mkdir my-proj && cd my-proj
    Tip

    To avoid losing your virtual environment upon exiting the container, create this folder in a directory mapped to one of your GPU Instance’s local volumes.

  5. Create a new virtual environment and generate a Pipfile:

    pipenv install
  6. Activate the virtual environment:

    pipenv shell

    Your prompt should indicate you are in the activated my-proj Pipenv virtual environment.

Going further

For more information, refer to the official Pipenv documentation.

See also
How to use the preinstalled environment
Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway