Skip to main content

Installing Packages

This guide helps you with the instructions to install and manage dependencies in your Python and JavaScript projects in Replit. Replit will install most available Python and JavaScript packages using the universal package manager.

Python

Log in to www.replit.com and create a new Python Repl. If this is your first time creating a Repl, follow this guide to create a new Repl.

Once your Python Repl is created, you can search and add packages by following the next section based on your workflow and project needs.

Search and add packages

In a Python Repl, open a new tab by selecting the + sign and searching for the Packages tool.

Packages View

You can search for packages from the Packages tool and select Install to add them to your project. Behind the scenes, the Packager tool uses upm search <term> as well as upm install <package_name>, if you'd prefer to manage your dependencies that way.

note

Unless otherwise specified, your Repl will attempt to install the latest version of each package.

Python package manager

upm
### upm (Universal Package Manager)

upm is a tool that provides a common interface across many underlying package managers. To see which languages and package managers are supported, please check out UPM: Supported Languages.

Key Features:

  • Simplified package installation and management.
  • Intelligent dependency guessing.
  • Comprehensive support for various Python environments.
pip

pip

pip is a commonly used package manager for Python. It's very stable and has been considered the standard package manager for years.

Key Features:

  • Well supported
  • Many examples online

When you create a Python Repl, by default, your package manager will be poetry. This means that you will not be able to use pip install to manage dependencies manually. Instead of running pip install <package>, you can instead run upm add <package>, which will do the same thing.

pip is one of the earliest, and consequently most popular, package managers for Python. You can use pip as your Repl's package manager instead of poetry. Follow the steps below:

  1. In the Tools pane, select the Shell tab to add the common requirements.txt file using the following command:

    touch requirements.txt

    You'll see that the requirements.txt has now been added to the Packager files.

  2. Delete the poetry.lock file.

  3. Move your dependencies from [tool.poetry.dependencies] to requirements.txt. Note that the flask = "^3.0.2" in pyproject.toml's [tool.poetry.dependencies] section would become flask>=3.0.2,<4 in requirements.txt.

  4. Finally, delete the other [tool.poetry...] sections from pyproject.toml.

After the above changes, the packaging infrastructure will use pip for all future operations.

Now, as you add code to your main.py file, any time you select Run, upm will determine whether there are any missing packages for your imports, find the latest versions of packages that provide those imports, and install them automatically.

poetry

Poetry

Poetry is a Python tool for managing dependencies and packaging, providing a straightforward workflow and ensuring reproducible builds with its poetry.lock file. In a Python Repl, poetry.lock and pyproject.toml are automatically included for easy project setup and management.

The pyproject.toml file provides a centralized location for storing project configuration and metadata, making managing project settings and dependencies easier. The poetry.lock file is used by the Poetry dependency management tool to lock the dependencies of a project to specific versions.

To install additional packages, navigate to your Workspace, then open a new tab by selecting the + sign and search for Packages. Choose the packages you want to install and select Install. When a new package is installed, the dependencies are added to the pyproject.toml. For example, installing flask adds it to the list of poetry dependencies:

[tool.poetry.dependencies]
python = "^3.8"
flask = "^1.1"

Import guessing

As your code evolves, we analyze your project for missing dependencies and automatically guess what needs to be installed to get your code to run. For example, if you add import flask to main.py, the next time you select Run, you'll see a section in the Console indicating that the latest version of Flask is being installed:

upm output showing packages being installed

Guessing failures

This section helps you with the command to run a particular version of your package. If there's a particular version that you need, or we guessed the wrong package entirely, you can run upm manually to resolve the conflict:

upm add 'flask==2.3.3' 

To install additional packages in your Workspace, open a new tab by selecting the + sign and searching for Packages. Select the packages of your choice and select Install. Additional options for package guessing can be configured in the .replit file.

JavaScript

Log in to www.replit.com and create a new JavaScript Repl or use an existing one. If this is your first time creating a Repl, follow this guide to create a new Repl.

Note that package.json files are only for Node.js/Express Repls (they do not apply to HTML/CSS/JS Repls). A package.json file contains project information and lists its dependencies. For example:

{
"name": "app",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {},
"author": "",
"license": "MIT",
"dependencies": {
"express": "latest",
"body-parser": "latest",
"sqlite3": "latest"
}
}

Direct imports

You can import the package directly into your JavaScript Repl using the following code. The following command uses express as an example dependency.

const express = require("express");

All the packages are installed with the latest version. For a specific version, replace latest with the version number or use a carat ^ to indicate compatible versions. For example:

  "dependencies": {
"express": "^4.16.3",
"body-parser": "latest",
"sqlite3": "3.1.12"
}

This installs express at 4.16.3 or newer (up until version 5.0.0), body-parser at the latest version, and sqlite3 at version 3.1.12.

Was this helpful?