Jump toUpdate content
How to use pipenv to create virtual environments
Pipenv is a package and dependency manager for Python projects. It harnesses the power of different existing tools, bringing their functionalities together:
- pip for Python package management
- pyenv for Python version management
- Virtualenv for creating different virtual Python environments
- Pipfile for managing project dependencies
Pipenv is pre-installed on all of Scaleway’s AI Docker images for GPU Instances. Launching one of these Docker images puts you in an activated pipenv virtual environment, with all your favourite packages and tools pre-installed. You can also use pipenv to create your own virtual environments, if you wish to go beyond the pre-installed Python environments already provided with the various Docker images.
See our dedicated documentation on how to access the pipenv virtual environment from your Scaleway GPU Instance.
You can view packages, install/uninstall packages and update packages with a few simple
Enter the following command to see all the packages and dependencies installed in this environment, and their versions:
Enter the following command to install a new package:
pipenv install <package>Tip:
To install a specific version of a package, use the command
pipenv install <package>~=1.2
Enter the following command to uninstall a package:
pipenv uninstall <package>
Enter the following command to update a package:
pipenv update <package>Tip:
To update all packages, simply run
Be aware that installing and updating packages may provoke conflicts with the existing virtual environment installation.
Every pipenv virtual environment has its own Pipfile. The Pipfile details the dependencies of the project, taking the place of the typical
requirements.txt file. When you create a Pipenv environment, a Pipfile is automatically generated.
From within the Docker container, in the
lsto list all files in this directory
The output should be similar to the following:
Enter the command
cat Pipfileto view the contents of Pipfile. The following information will help you understand the output:
sourcespecifies the sources where available packages are added/installed from
packageslists the packages required for the project (production and development environments)
dev-packageslists the packages required for the project (development environments only)
requiresspecifes the required python version for the project
Any packages that you explicitly install with the command
pipenv install <package>will automatically be added to the Pipfile. If you push your project to a Git repository, other users who clone it will be able to install all dependencies, based on the Pipfile, with the command
Enter the command
cat Pipfile.lockto view the contents of Pipfile.lock.
This file specifies which specific versions of the packages in the Pipfile should be used. This prevents packages which depend on each other being automatically upgraded, which could break your project dependency tree.
You are now in the
~/aidirectory of the Docker container, with the virtual environment activated.
exitto exit the virtual environment.
cd ~to leave the
~/aidirectory and go to the home directory.
Create a new project directory for your new virtual environment, and navigate into it. Replace
my-projwith the desired name for your project.
mkdir my-proj && cd my-projTip:
To avoid losing your virtual environment upon exiting the container, make sure you create this folder in a directory that is mapped to one of your GPU Instance’s local volumes
Create a new virtual environment and generate a Pipfile:
Activate the virtual environment:
Your command prompt should now be similar to
(my-proj) jovyan@442a38468c20:~/my-proj, showing that you are in the activated
my-projpipenv virtual environment.
See the official Pipenv documentation for further help with Pipenv.