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 | bash
Where 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"' >> ~/.bashrc
Zsh
echo 'source "$HOME/.rye/env"' >> ~/.zshrc
Fish
set -Ua fish_user_paths "$HOME/.rye/shims"
Unix Shells
echo '. "$HOME/.rye/env"' >> ~/.profile
Windows
- 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\shims
and 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 --version
For 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 init
It'll initialize the project with the following:
$ .
├── pyproject.toml
├── .python-version
└── src
└── rye
└── __init__.py
2 directories, 3 files
When initializing the project, rye would use its shimed Python version,
$ which python
~/.rye/shims/python
On my system, the Python version is:
$ python --version
Python 3.12.0
Therefore, in .python-version
,
cpython-x86_64-linux@3.12.0
Next, run this command to create the virtual environment:
$ rye sync
The 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 files
You can spawn a shell with the Python environment activation
$ rye shell
However, 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,
$ exit
Remove the virtual environment,
$ rm -rf .venv
To use a different Python version, you can use the following command to setup,
For example
$ rye pin 3.11
which would update the .python-version
file,
3.11.6
Then, run sync to apply the change,
$ rye sync
It 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!