Rye is built by Armin Ronacher, it is a personal one-stop-shop for all Python needs, but still an experimental package management solution.
For Linux/MacOS users,
$ curl -sSf https://rye-up.com/get | bashWhere rye got installed?
This installer will install rye to ~/.rye
This path can be changed by exporting the `RYE_HOME` environment variable.For Windows users, you can install the .exe file,
- rye-x86_64-windows.exe for 64bit Intel Windows
- rye-x86-windows.exe for 32bit Intel Windows
Bash
echo 'source "$HOME/.rye/env"' >> ~/.bashrcZsh
echo 'source "$HOME/.rye/env"' >> ~/.zshrcFish
set -Ua fish_user_paths "$HOME/.rye/shims"Unix Shells
echo '. "$HOME/.rye/env"' >> ~/.profileWindows
- Press
Win+R, enter sysdm.cpl and hit Enter. - In the "System Properties" dialog, click the "Advanced" tab.
- Click on "Environment Variables".
- In the top list, double click on the Path variable.
- In the "Edit environment variable" dialog click on "New".
- Enter
%USERPROFILE%\.rye\shimsand hit Enter. - Click repeatedly on "Move Up" until the newly added item is at the top.
- Click on "OK" and close the dialog.
Run the following command to validate the installation:
$ rye --versionFor more information about rye installation, please see the documentation
To use Rye you need to have a pyproject.toml based Python project. If not, then you need to run:
$ rye initIt'll initialize the project with the following:
$ .
├── pyproject.toml
├── .python-version
└── src
└── rye
└── __init__.py
2 directories, 3 filesWhen initializing the project, rye would use its shimed Python version,
$ which python
~/.rye/shims/pythonOn my system, the Python version is:
$ python --version
Python 3.12.0Therefore, in .python-version,
cpython-x86_64-linux@3.12.0Next, run this command to create the virtual environment:
$ rye syncThe virtual environment that Rye manages is placed in .venv next to the pyproject.toml.
.venv
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate.nu
│ ├── activate.ps1
│ ├── activate_this.py
│ ├── hello
│ ├── python -> ~/.rye/py/cpython@3.12.0/install/bin/python3
│ ├── python3 -> python
│ └── python3.12 -> python
├── lib
│ └── python3.12
├── pyvenv.cfg
└── rye-venv.json
3 directories, 12 filesYou can spawn a shell with the Python environment activation
$ rye shellHowever, there is one notable exception: the Python installation in it does not contain pip.
Use the add command to add dependencies to your project.
$ rye add <package1> <package2> ...If you like to add dependencies for development only, then
$ rye add --dev <package1> <package2> ...To remove the dependencies,
$ rye remove <package1> <package2> ...Rye currently uses pip-tools to download and install dependencies,
and it creates two "lockfiles" (called requirements.lock and requirements-dev.lock).
Whenever rye sync is called, it will update lockfiles as well as the virtual environment.
If you only want to update the lockfiles, then rye lock can be used.
Run exit to deactivate the current virtual environment,
$ exitRemove the virtual environment,
$ rm -rf .venvTo use a different Python version, you can use the following command to setup,
For example
$ rye pin 3.11which would update the .python-version file,
3.11.6Then, run sync to apply the change,
$ rye syncIt will create the new virtual environment based on Python version 3.11.6.
For more usage information of rye, please see the official documentation.
Happy Coding!