### Customized Windows Installation with Specific Toolchain Source: https://github.com/astral-sh/rye/blob/main/docs/guide/installation.md On Windows, you can customize the installation by setting environment variables before running the installer. This example installs Rye with a specific Python toolchain. ```batch set RYE_TOOLCHAIN=%USERPROFILE%\AppData\Local\Programs\Python\Python310\python.exe rye-x86_64-windows.exe ``` -------------------------------- ### Quick Install Script Source: https://github.com/astral-sh/rye/blob/main/docs/guide/installation.md Use this command to quickly install Rye. It downloads and executes a script that sets up Rye in your user directory. ```bash curl -sSf https://rye-install.sh | bash ``` -------------------------------- ### Dockerfile for Installable Package with uv Source: https://github.com/astral-sh/rye/blob/main/docs/guide/docker.md Containerize an installable Python package by building it first, then installing the wheel inside the Docker image using uv. ```docker FROM python:slim RUN pip install uv RUN --mount=source=dist,target=/dist uv pip install --no-cache /dist/*.whl CMD python -m my_package ``` -------------------------------- ### Install System Dependencies in Dockerfile Source: https://github.com/astral-sh/rye/blob/main/docs/guide/docker.md Example of how to install additional system packages within a Debian-based Docker image before copying application source code. ```docker RUN apt-get update \ && apt-get install -y --no-install-recommends some-dependency another-dependency \ && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### List Installed Dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/list.md Run this command in your project directory to see a list of all installed packages and their versions. ```bash $ rye list asgiref==3.7.2 blinker==1.7.0 click==8.1.7 Flask @ git+https://github.com/pallets/flask@4df377cfbfc1d15e962a61c18920b22aebc9aa41 itsdangerous==2.1.2 Jinja2==3.1.3 MarkupSafe==2.1.4 Werkzeug==3.0.1 ``` -------------------------------- ### Install a package as a global tool Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/install.md Use this command to install a Python package globally. This makes its executable scripts available in your PATH. The example shows installing `pycowsay` and then running it. ```bash $ rye tools install pycowsay Looking in indexes: https://pypi.org/simple/ Collecting pycowsay Downloading pycowsay-0.0.0.2-py3-none-any.whl.metadata (965 bytes) Downloading pycowsay-0.0.0.2-py3-none-any.whl (4.0 kB) Installing collected packages: pycowsay Successfully installed pycowsay-0.0.0.2 Installed scripts: - pycowsay $ pycowsay "Great Stuff" ----------- < Great Stuff > ----------- \ ^__^ \ (oo)\_______ (__)\ )\/\n ||----w | || || ``` -------------------------------- ### List installed tools Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/tools/list.md Use this command to see a list of all globally installed tools. ```bash rye tools list ``` -------------------------------- ### List Installed Tools Source: https://github.com/astral-sh/rye/blob/main/docs/guide/tools.md View all globally installed tools. Pass `--include-scripts` to also see the scripts provided by these tools. ```bash rye tools list ``` ```bash rye tools list --include-scripts ``` -------------------------------- ### Customized Linux Installation Source: https://github.com/astral-sh/rye/blob/main/docs/guide/installation.md On Linux, you can customize the installation by passing options to the installation script via environment variables. ```bash curl -sSf https://rye-install.sh | RYE_INSTALL_OPTION=--skip-toolchain=python3.11 python3 - --install-dir $HOME/.rye ``` -------------------------------- ### Install Maturin as a Global Tool Source: https://github.com/astral-sh/rye/blob/main/docs/guide/rust.md Install Maturin as a global tool using `rye install` to access its commands. ```bash rye install maturin ``` -------------------------------- ### Install Rye on Linux/macOS Source: https://github.com/astral-sh/rye/blob/main/README.md Use this command to install Rye on Linux and macOS systems. It fetches and executes the installation script. ```bash curl -sSf https://rye.astral.sh/get | bash ``` -------------------------------- ### List installed tools with version Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/tools/list.md To display the installed tools along with their versions and associated Python interpreter, use the `--include-version` flag. ```bash rye tools list --include-version ``` -------------------------------- ### Dockerfile for Installable Package (Wheel-Based) Source: https://context7.com/astral-sh/rye/llms.txt This Dockerfile installs a project's wheel distribution from a `dist` directory using `uv`. It assumes the wheel has been built separately. ```docker # Dockerfile for an installable package (wheel-based) FROM python:3.12-slim RUN pip install uv WORKDIR /app RUN --mount=source=dist,target=/dist \ uv pip install --no-cache --system /dist/*.whl CMD ["python", "-m", "my_package"] ``` -------------------------------- ### Install a Package as a Global Tool Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/tools/install.md Installs the `pycowsay` package as a global tool and then demonstrates its usage. This is useful for installing Python scripts globally into a separate virtual environment. ```bash $ rye tools install pycowsay Looking in indexes: https://pypi.org/simple/ Collecting pycowsay Downloading pycowsay-0.0.0.2-py3-none-any.whl.metadata (965 bytes) Downloading pycowsay-0.0.0.2-py3-none-any.whl (4.0 kB) Installing collected packages: pycowsay Successfully installed pycowsay-0.0.0.2 Installed scripts: - pycowsay $ pycowsay "Great Stuff" ----------- < Great Stuff > ----------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || ``` -------------------------------- ### List Downloadable Toolchains Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/toolchain/list.md Lists both installed and downloadable Python toolchains. This helps in identifying which toolchains can be installed. ```bash $ rye toolchain list --include-downloadable cpython@3.12.1 (/Users/mitsuhiko/.rye/py/cpython@3.12.1/install/bin/python3) cpython-x86_64@3.12.1 (downloadable) cpython@3.11.7 (downloadable) ... ``` -------------------------------- ### Install a Global Tool with Rye Source: https://github.com/astral-sh/rye/blob/main/docs/guide/tools.md Use this command to install a tool globally. Rye creates shims for the tool in a dedicated directory. ```bash rye install ruff ``` -------------------------------- ### Install Latest Stable Managed Python with uv Source: https://github.com/astral-sh/rye/blob/main/docs/guide/uv.md Installs the latest stable managed Python version. Use `--default` to also install `python` and `python3` commands. ```bash uv python install ``` ```bash uv python install --default ``` -------------------------------- ### List Installed Toolchains Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md Run `rye toolchain list` to display all currently installed Python toolchains managed by Rye, including their installation paths. ```bash rye toolchain list ``` -------------------------------- ### List installed dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/basics.md Execute `rye list` to view all dependencies currently installed in your project's virtual environment. Ensure you have run `rye sync` beforehand for an accurate list. ```shell rye list ``` -------------------------------- ### List All Available Toolchains (Including Downloadable) Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md To see all toolchains that Rye can install, including those not yet downloaded, use the `--include-downloadable` flag with `rye toolchain list`. ```bash rye toolchain list --include-downloadable ``` -------------------------------- ### List Installed Toolchains Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/toolchain/list.md Lists all currently installed Python toolchains managed by Rye. This is useful for quickly seeing available environments. ```bash $ rye toolchain list cpython@3.12.1 (/Users/username/.rye/py/cpython@3.12.1/install/bin/python3) cpython@3.11.6 (/Users/username/.rye/py/cpython@3.11.6/install/bin/python3) ``` -------------------------------- ### Enable Fetching Python with Build Info Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md Use this command to configure Rye to fetch Python installations with build information included. This is useful for older Rye versions or specific development needs. ```bash rye config --set-bool behavior.fetch-with-build-info=true ``` -------------------------------- ### Install and Configure Rye Source: https://context7.com/astral-sh/rye/llms.txt Installs Rye using the official script and configures shell environment variables for its shims. Includes commands for updating and uninstalling Rye, and generating shell completions. ```bash # Install Rye (Linux/macOS) curl -sSf https://rye.astral.sh/get | bash ``` ```bash # Add shims to PATH (Bash) echo 'source "$HOME/.rye/env"' >> ~/.bashrc source ~/.bashrc ``` ```bash # Add shims to PATH (Zsh) echo 'source "$HOME/.rye/env"' >> ~/.zprofile ``` ```bash # Add shims to PATH (Fish) set -Ua fish_user_paths "$HOME/.rye/shims" ``` ```bash # Update Rye to the latest version rye self update ``` ```bash # Uninstall Rye rye self uninstall ``` ```bash # Generate shell completions (Bash example) mkdir -p ~/.local/share/bash-completion/completions rye self completion > ~/.local/share/bash-completion/completions/rye.bash ``` -------------------------------- ### Enable all package features Source: https://github.com/astral-sh/rye/blob/main/docs/guide/sync.md Use `--all-features` to enable all available features for package installation. This is a shortcut for specifying all features individually. ```bash rye lock --all-features ``` -------------------------------- ### Sync Project Dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/sync.md Use this command to synchronize your project's dependencies with the lockfile and install them into the virtual environment. This is the default behavior of the `sync` command. ```bash $ rye sync Reusing already existing virtualenv Generating production lockfile: /Users/username/my-project/requirements.lock Generating dev lockfile: /Users/username/my-project/requirements-dev.lock Installing dependencies ... ``` -------------------------------- ### Synchronize project dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/basics.md Run `rye sync` to install project dependencies, create a virtual environment in `.venv`, and generate lockfiles. This command also automatically downloads and installs a compatible Python interpreter if one is not already available. ```shell rye sync ``` -------------------------------- ### Add PyTorch Packages with Rye Source: https://github.com/astral-sh/rye/blob/main/docs/guide/faq.md Install PyTorch, torchvision, and torchaudio using the rye add command after configuring sources. ```bash rye add torch torchvision torchaudio ``` -------------------------------- ### Define Project Scripts Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Specify scripts to be generated and installed into the virtual environment during `sync`. These scripts invoke configured entry points. ```toml [project.scripts] my-hello-script = 'hello:main' ``` -------------------------------- ### Storing Additional Dependency Metadata (Attempt 1) Source: https://github.com/astral-sh/rye/blob/main/notes/pep508.md A conceptual example showing how additional metadata might be stored by indexing into a separate table based on the dependency's position in the `dependencies` array. This approach is a workaround for PEP 508's limitations. ```toml [tool.rye.dependencies_meta.0] extra_information = 42 ``` -------------------------------- ### Run a tool from the virtualenv Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/run.md Execute a tool like 'flask' that is installed in the virtual environment. This command assumes 'flask' is available. ```bash $ rye run flask ``` -------------------------------- ### Inspect Project State Source: https://context7.com/astral-sh/rye/llms.txt Displays information about the current project, including Python version, virtualenv path, and installed packages. 'rye list' shows installed packages after syncing. ```bash rye show ``` ```bash rye list ``` -------------------------------- ### Install Tool with Extra Requirements Source: https://github.com/astral-sh/rye/blob/main/docs/guide/tools.md When a tool has optional dependencies or requires specific packages not declared, use the `--features` or `--extra-requirement` flags. ```bash rye install black --features colorama ``` ```bash rye install gradio --extra-requirement setuptools ``` -------------------------------- ### Add and Sync Packages with Rye Source: https://context7.com/astral-sh/rye/llms.txt After configuring custom sources, use `rye add` to specify packages and `rye sync` to install them based on the project's configuration. ```bash # After configuring the pytorch source, add packages normally rye add torch torchvision torchaudio rye sync ``` -------------------------------- ### Cargo Local Dependency Example Source: https://github.com/astral-sh/rye/blob/main/notes/pep508.md Illustrates how Cargo specifies local dependencies with version and path information. The 'path' marker is removed upon publishing. ```toml [dependencies] foo = { version = "1.0", path = "../crates" } ``` -------------------------------- ### Install Rye with PATH Priority on Linux Source: https://github.com/astral-sh/rye/blob/main/docs/guide/faq.md Reinstall Rye with higher priority for the system's PATH to resolve potential 'ldd' conflicts. ```bash export PATH="/usr/bin:$PATH" curl -sSf https://rye.astral.sh/get | bash ``` -------------------------------- ### Declare a Virtual Project Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Declare a project as virtual by setting `tool.rye.virtual = true`. In this mode, the package itself is not installed, only its dependencies. ```toml [tool.rye] virtual = true ``` -------------------------------- ### Add PyTorch Sources to pyproject.toml Source: https://github.com/astral-sh/rye/blob/main/docs/guide/faq.md Configure PyTorch sources in your project's pyproject.toml file for installation. ```toml [[tool.rye.sources]] name = "pytorch" url = "https://download.pytorch.org/whl/cpu" ``` -------------------------------- ### Build Wheel and Docker Image with Rye Source: https://context7.com/astral-sh/rye/llms.txt Build a project's wheel distribution using `rye build --wheel` and then use `docker build` to create a container image. This process is suitable for packaging installable Python projects. ```bash # Build the wheel first, then package into Docker image rye build --wheel --clean docker build . --tag my-app:latest ``` -------------------------------- ### Manage Python Toolchains Source: https://context7.com/astral-sh/rye/llms.txt Manages Python interpreter installations (toolchains), downloading CPython or PyPy. Supports listing, fetching, pinning, registering, and removing toolchains. ```bash rye toolchain list ``` ```bash rye toolchain list --include-downloadable ``` ```bash rye toolchain fetch cpython@3.8.5 ``` ```bash rye toolchain fetch pypy@3.9.16 ``` ```bash rye pin 3.10 rye fetch # alias for rye toolchain fetch ``` ```bash rye toolchain fetch cpython@3.8.5 --target-path=./my-interpreter ``` ```bash rye toolchain register /usr/local/bin/python3 ``` ```bash rye toolchain register --name=my-debug-py /path/to/python-debug ``` ```bash rye toolchain remove cpython@3.8.5 ``` -------------------------------- ### Initialize and Use a Virtual Project Source: https://github.com/astral-sh/rye/blob/main/docs/guide/virtual.md Use these commands to initialize a virtual project, add dependencies like MkDocs, sync them, and then run the tool. ```bash rye init --virtual rye add mkdocs rye sync rye run mkdocs ``` -------------------------------- ### Fetch Toolchain Based on Current Pin Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md Starting with Rye 0.19.0, you can fetch the toolchain specified by the current project's pin by first pinning it and then running `rye fetch`. ```bash rye pin 3.10 rye fetch ``` -------------------------------- ### Print Help Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/sync.md Use the `-h` or `--help` option to print a summary of the `sync` command's options and arguments. ```bash -h ``` ```bash --help ``` -------------------------------- ### Add a dependency Source: https://github.com/astral-sh/rye/blob/main/docs/guide/basics.md Use `rye add` to include new dependencies in your project. Remember to run `rye sync` afterwards to install the added package into the virtual environment. For custom indexes, configure sources first. ```shell rye add "flask>=2.0" ``` -------------------------------- ### Dockerfile for Virtual/Source-Based Projects Source: https://context7.com/astral-sh/rye/llms.txt This Dockerfile installs dependencies using `uv` from `requirements.lock` and copies source code. It's designed for projects that are not packaged as wheels. ```docker # Dockerfile for a virtual/source-based project (no installable package) FROM python:3.12-slim RUN pip install uv WORKDIR /app COPY requirements.lock ./ RUN uv pip install --no-cache --system -r requirements.lock COPY src . CMD ["python", "main.py"] ``` -------------------------------- ### Fetch Toolchain to a Specific Target Path Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md Use the `--target-path` option with `rye toolchain fetch` to download a toolchain to a custom location, useful for debugging or advanced setups. This interpreter will not be automatically managed by Rye unless registered. ```bash rye toolchain fetch cpython@3.8.5 --target-path=my-interpreter ``` -------------------------------- ### Manipulating Rye Configuration via CLI Source: https://github.com/astral-sh/rye/blob/main/docs/guide/config.md Use the `rye config` command to set, get, or unset configuration values. Keys are specified using dotted notation. Examples show setting proxy and behavior options, and retrieving the default Python requirement. ```bash rye config --set proxy.http=http://127.0.0.1:4000 ``` ```bash rye config --set-bool behavior.force-rye-managed=true ``` ```bash rye config --get default.requires-python ``` -------------------------------- ### Initialize a new project Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/init.md Run this command in a directory to initialize a new Python project with Rye. It will create necessary configuration files and suggest the next steps. ```bash $ rye init success: Initialized project in /Users/john/Development/my-project. Run `rye sync` to get started ``` -------------------------------- ### Pip Requirements File with Wheel URL and Markers Source: https://github.com/astral-sh/rye/blob/main/notes/markers.md This example shows a pip requirements file using direct wheel URLs with environment markers. It specifies different wheels for Linux and macOS, targeting specific Python versions (3.9 and 3.10) for each platform. ```pip "awesome_package @ https://example.com/awesome_package-cp39-cp39-linux_x86_64.whl ; sys_platform == 'linux' and python_version == '3.9'", "awesome_package @ https://example.com/awesome_package-cp310-cp310-linux_x86_64.whl ; sys_platform == 'linux' and python_version == '3.10'", "awesome_package @ https://example.com/python/awesome_package-cp39-cp39-macosx_12_0_x86_64.whl ; sys_platform == 'darwin' and python_version == '3.9'", "awesome_package @ https://example.com/python/awesome_package-cp310-cp310-macosx_12_0_x86_64.whl ; sys_platform == 'darwin' and python_version == '3.10'" ``` -------------------------------- ### Build and Publish Packages Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/publish.md First build your packages using `rye build`, then publish them to the repository with `rye publish`. This is the standard workflow for releasing new versions. ```bash $ rye build $ rye publish ``` -------------------------------- ### Define Development Dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Manage development-only dependencies using `tool.rye.dev-dependencies`. These are automatically added with `rye add --dev` and installed unless `--no-dev` is passed to `sync`. ```toml [tool.rye] dev-dependencies = ["black~=23.3.0"] ``` -------------------------------- ### Register a Python binary Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/toolchain/register.md Use this command to register an existing Python binary. The toolchain name is auto-detected from the binary path. For example, registering a Python 3.10.6 binary results in a toolchain named `cpython@3.10.6`. ```bash $ rye toolchain register /opt/homebrew/Cellar/python@3.10/3.10.6_1/bin/python3.10 Registered /opt/homebrew/Cellar/python@3.10/3.10.6_1/bin/python3.10 as cpython@3.10.6 ``` -------------------------------- ### Initialize a new Rye project Source: https://github.com/astral-sh/rye/blob/main/docs/guide/basics.md Use `rye init` to create a new project with a `pyproject.toml` file. This command accepts options to customize the generated project structure. Run `rye init --help` for available options. ```shell rye init my-project cd my-project ``` -------------------------------- ### Create Project with Executable Script using uv Source: https://github.com/astral-sh/rye/blob/main/docs/guide/uv.md Initializes a project with an executable script runnable via `uv run`. This command creates a single-file executable script with a PEP 723 header that supports dependencies. ```bash uv init --package ``` ```bash uv init --script ``` -------------------------------- ### Enable specific package features Source: https://github.com/astral-sh/rye/blob/main/docs/guide/sync.md Install dependencies with specific features enabled using the `--features` flag. For workspace packages, prefix the feature name with the package name and a slash. Features can be comma-separated or passed multiple times. ```bash rye add --optional=web flask rye lock --features=web ``` ```bash rye lock --features=package-name/feature-name ``` -------------------------------- ### Manage Global Rye Configuration Source: https://context7.com/astral-sh/rye/llms.txt Configure Rye's default behavior across all projects using 'rye config'. This includes setting toolchains, proxies, and build systems. Use '--get', '--set', '--set-bool', and '--unset' for management. ```bash # Read a config value rye config --get default.requires-python # Set string values rye config --set proxy.http=http://127.0.0.1:4000 rye config --set default.toolchain=cpython@3.12.0 rye config --set default.build-system=hatchling # Set boolean values rye config --set-bool behavior.force-rye-managed=true rye config --set-bool behavior.global-python=true rye config --set-bool behavior.autosync=true # Unset a value rye config --unset proxy.http ``` -------------------------------- ### Show config path Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/config.md Prints the absolute path to the global configuration file. ```bash $ rye config --show-path /Users/username/.rye/config.toml ``` -------------------------------- ### Prevent Rye Auto Installation Source: https://github.com/astral-sh/rye/blob/main/docs/guide/installation.md Export RYE_NO_AUTO_INSTALL to '1' to disable automatic installation behavior in certain development scenarios. ```bash export RYE_NO_AUTO_INSTALL=1 ``` ```bash set RYE_NO_AUTO_INSTALL=1 ``` -------------------------------- ### Build Wheel and Docker Image for Package Source: https://github.com/astral-sh/rye/blob/main/docs/guide/docker.md Commands to first build a Python wheel for your package and then build the Docker image, tagging it with a custom name. ```bash rye build --wheel --clean docker build . --tag your-image-name ``` -------------------------------- ### Sync and run executable script Source: https://github.com/astral-sh/rye/blob/main/docs/guide/basics.md After initializing an executable project and syncing dependencies, you can run the main script using `rye run` followed by the script name. ```shell rye sync rye run my-project ``` -------------------------------- ### Initialize an executable project Source: https://github.com/astral-sh/rye/blob/main/docs/guide/basics.md Use `rye init --script` to generate a project structure suitable for providing an executable script. This adds a `__main__.py` file and configures the `[project.scripts]` section in `pyproject.toml`. ```shell rye init --script my-project cd my-project ``` -------------------------------- ### Initialize New Rust Project with Maturin Source: https://github.com/astral-sh/rye/blob/main/docs/guide/rust.md Use `rye init` to create a new project with Maturin as the build system. Navigate into the project directory afterwards. ```bash rye init my-project --build-system maturin cd my-project ``` -------------------------------- ### Uninstall a Global Tool with Rye Source: https://context7.com/astral-sh/rye/llms.txt Use 'rye uninstall' or 'rye tools uninstall' to remove a globally installed tool. This command is useful for managing globally available CLI tools installed by Rye. ```bash rye uninstall black rye tools uninstall black ``` -------------------------------- ### Initialize a New Python Project with Rye Source: https://context7.com/astral-sh/rye/llms.txt Creates a new Python project structure including `pyproject.toml`, `src/` layout, and `.python-version` file. Supports options for adding a CLI entry point or creating a virtual project. ```bash # Create a standard library/application project rye init my-project cd my-project # Result: # . # ├── .git # ├── .gitignore # ├── .python-version # ├── README.md # ├── pyproject.toml # └── src/my_project/__init__.py ``` ```bash # Create a project with a CLI executable entry point rye init --script my-cli-app # Generates pyproject.toml with [project.scripts] pointing to main() ``` ```bash # Create a virtual (non-installable) project — useful for tools, scripts, Docker rye init --virtual my-env ``` ```bash # Initialize in the current directory rye init ``` ```bash # Show all available options rye init --help ``` -------------------------------- ### Manage Global Python Tools Source: https://context7.com/astral-sh/rye/llms.txt Installs Python CLI tools globally with shims, isolated from project virtualenvs. Supports installing tools, with optional extras or unlisted requirements, and listing tools with their provided scripts. ```bash rye install ruff ``` ```bash rye install black ``` ```bash rye install httpie ``` ```bash rye install black --features colorama ``` ```bash rye install gradio --extra-requirement setuptools ``` ```bash rye tools list ``` ```bash # List tools and the scripts they provide rye tools list --include-scripts ``` -------------------------------- ### Uninstall a Global Tool Source: https://github.com/astral-sh/rye/blob/main/docs/guide/tools.md Use this command to remove a globally installed tool and its associated shims. ```bash rye uninstall black ``` -------------------------------- ### Get config value Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/config.md Reads the currently set configuration value for a specific key, such as `behavior.global-python`. ```bash $ rye config --get behavior.global-python true ``` -------------------------------- ### Add pytest as a dev dependency Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/test.md Before running tests, install `pytest` as a development dependency using Rye. ```bash $ rye add --dev pytest ``` -------------------------------- ### Configure Index with Basic Auth (Configured Credentials) Source: https://github.com/astral-sh/rye/blob/main/docs/guide/sources.md Provide username and password directly in the configuration for HTTP basic authentication to an index. ```toml [[sources]] name = "company-internal" url = "https://company.internal/simple/" username = "username" password = "super secret" ``` -------------------------------- ### Get Current Project Version Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/version.md Use this command to display the current version of your project as specified in `pyproject.toml`. ```bash $ rye version 0.1.0 ``` -------------------------------- ### Uninstall a Global Tool Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/tools/uninstall.md Use this command to remove a globally installed tool. Specify the name of the tool to uninstall. ```bash $ rye tools uninstall pycowsay Uninstalled pycowsay ``` -------------------------------- ### OpenCV-Python Dependency Markers Source: https://github.com/astral-sh/rye/blob/main/notes/markers.md Example of complex dependency markers used by `opencv-python`, illustrating version and platform-specific constraints. ```text numpy >=1.13.3 ; python_version < "3.7" numpy >=1.21.0 ; python_version <= "3.9" and platform_system == "Darwin" and platform_machine == "arm64" numpy >=1.21.2 ; python_version >= "3.10" numpy >=1.21.4 ; python_version >= "3.10" and platform_system == "Darwin" numpy >=1.23.5 ; python_version >= "3.11" numpy >=1.19.3 ; python_version >= "3.6" and platform_system == "Linux" and platform_machine == "aarch64" numpy >=1.17.0 ; python_version >= "3.7" numpy >=1.17.3 ; python_version >= "3.8" numpy >=1.19.3 ; python_version >= "3.9" ``` -------------------------------- ### Add a Basic Dependency Source: https://github.com/astral-sh/rye/blob/main/docs/guide/deps.md Use `rye add` followed by the package name to add a regular dependency to your project. ```bash rye add Flask ``` -------------------------------- ### Format Code and Write Back Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/fmt.md Use this command to format all code files in the project and write the changes back to the files. ```bash $ rye fmt 1 file reformatted, 231 files left unchanged ``` -------------------------------- ### Include Sources in Lockfile Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/sync.md Set `--with-sources` to true to include package sources in the lockfile. This can be useful for reproducibility or offline installations. ```bash --with-sources ``` -------------------------------- ### Exclude Dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Specify dependencies that should never be installed, even if pulled in indirectly, using `tool.rye.excluded-dependencies`. These are added with `rye add --excluded`. ```toml [tool.rye] excluded-dependencies = ["cffi"] ``` -------------------------------- ### Configure Index with Basic Auth (Environment Variables) Source: https://github.com/astral-sh/rye/blob/main/docs/guide/sources.md Use environment variables for username and password to authenticate with an index via HTTP basic auth. The URL must be formatted to include these variables. ```toml [[sources]] name = "company-internal" url = "https://${INDEX_USERNAME}:${INDEX_PASSWORD}@company.internal/simple/" ``` -------------------------------- ### Configure Dependency Sources Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Define custom dependency sources using `tool.rye.sources`. This allows using indexes other than PyPI. Configuration can also be done in `config.toml`. ```toml [[tool.rye.sources]] name = "default" url = "http://pypi.org/simple/" ``` -------------------------------- ### Pin a Specific CPython Version Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md Use this command to pin a project to a precise CPython version. Rye will automatically fetch it if not already installed. ```bash rye pin cpython@3.11.4 ``` -------------------------------- ### Dockerfile for Virtual Project with uv Source: https://github.com/astral-sh/rye/blob/main/docs/guide/docker.md Use this Dockerfile to containerize a Python project configured as a virtual project. It leverages uv for dependency installation. ```docker FROM python:slim RUN pip install uv WORKDIR /app COPY requirements.lock ./ RUN uv pip install --no-cache --system -r requirements.lock COPY src . CMD python main.py ``` -------------------------------- ### Dockerfile for Virtual Project with pip Source: https://github.com/astral-sh/rye/blob/main/docs/guide/docker.md An alternative Dockerfile for virtual projects that uses pip for dependency installation. It includes PYTHONDONTWRITEBYTECODE to reduce image size. ```docker FROM python:slim WORKDIR /app COPY requirements.lock ./ RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -r requirements.lock COPY src . CMD python main.py ``` -------------------------------- ### Update Rye to a Specific Version Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/self/update.md Install a particular version of Rye, including older versions, by specifying the version number with the `--version` flag. ```bash $ rye self update --version 0.20 ``` -------------------------------- ### Adding Extra Information to Dependencies (Object Format) Source: https://github.com/astral-sh/rye/blob/main/notes/pep508.md Demonstrates how extra information could be directly embedded within the dependency specification if the format allowed objects instead of just strings. This is a hypothetical format. ```toml [project.dependencies] Flask = { version = ">=2.0", extra_information = 42 } ``` -------------------------------- ### Add a Git dependency Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/add.md Add a dependency directly from a Git repository. This is useful for installing packages not yet published to PyPI or for using specific branches/tags. ```bash $ rye add flask --git https://github.com/pallets/flask Added flask @ git+https://github.com/pallets/flask as regular dependency ``` -------------------------------- ### Pass Extra Arguments to Formatter Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/fmt.md Forward extra arguments to the underlying `ruff` formatter using the `--` marker. This example shows how to generate a diff. ```bash $ rye fmt -- --diff ---src/my_project/utils.py +++src/my_project/utils.py @@ -2,5 +2,4 @@ def foo(): - pass + pass 1 file would be reformatted, 231 files already formatted ``` -------------------------------- ### Add a Pre-release Dependency Source: https://github.com/astral-sh/rye/blob/main/docs/guide/deps.md Include pre-release versions of a dependency by using the `--pre` flag. ```bash rye add "Flask==2.0.0rc2" --pre ``` -------------------------------- ### Pass extra arguments to the linter Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/lint.md Forward additional arguments to the underlying linter (Ruff) by using the `--` marker. For example, to enable watch mode. ```bash $ rye lint -- --watch ``` -------------------------------- ### Configure Rye Workspace Members Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Declare a project as a workspace root using `[tool.rye.workspace]`. Optionally restrict members using the `members` key with globs. ```toml [tool.rye.workspace] members = ["mylib-*"] ``` -------------------------------- ### Build Docker Image for Virtual Project Source: https://github.com/astral-sh/rye/blob/main/docs/guide/docker.md Command to build a Docker image from the current project directory, assuming a Dockerfile is present. ```bash docker build . ``` -------------------------------- ### Force Reinstallation of Rye Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/self/update.md Use the `--force` flag to ensure Rye is reinstalled, even if it appears to be up-to-date. This can resolve issues caused by corrupted installations. ```bash $ rye self update --force ``` -------------------------------- ### Publish with Token and Skip Confirmation Source: https://github.com/astral-sh/rye/blob/main/docs/guide/publish.md Publishes package distribution files using a provided access token and skips the confirmation prompt. Useful for automated CI/CD pipelines. ```bash rye publish --token --yes ``` -------------------------------- ### Build Package with Rye Source: https://github.com/astral-sh/rye/blob/main/docs/guide/publish.md Builds both sdist and wheel targets in the default 'dist' directory. Use this command to create distributable package files. ```bash rye build ``` -------------------------------- ### Uninstall Rye Non-interactively Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/self/uninstall.md Use the `--yes` flag to uninstall rye without prompting for confirmation. This command will remove the rye installation but leave a trace `.rye` folder. ```bash $ rye self uninstall --yes ``` -------------------------------- ### List Toolchains in JSON Format Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/toolchain/list.md Requests parseable output in JSON format for the list of toolchains. This is useful for scripting and automation. ```bash $ rye toolchain list --format json ``` -------------------------------- ### Specify Pyproject.toml File Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/sync.md Use the `--pyproject` option to specify an alternative `pyproject.toml` file to use for the project configuration. Replace `` with the path to the file. ```bash --pyproject ``` -------------------------------- ### Run External Tools with uvx Source: https://github.com/astral-sh/rye/blob/main/docs/guide/uv.md Executes external tools like Ruff without installing them into the project. Note: This does not work for tools like pytest that need to run project code. ```bash uvx ruff ``` -------------------------------- ### Add Git or Local Dependencies Source: https://github.com/astral-sh/rye/blob/main/docs/guide/deps.md Add dependencies hosted on Git repositories or local paths using `--git` or `--path` flags, respectively. Package name is required. ```bash rye add Flask --git=https://github.com/pallets/flask ``` ```bash rye add My-Utility --path ./my-utility ``` -------------------------------- ### Register an External Python Interpreter Source: https://github.com/astral-sh/rye/blob/main/docs/guide/toolchains/index.md Use `rye toolchain register` to add a locally installed Python interpreter to Rye's management. Rye will infer the toolchain name based on the interpreter. ```bash rye toolchain register /path/to/python ``` -------------------------------- ### Enable All Features Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/sync.md Use the `--all-features` option to enable all available features for the workspace during the locking process. ```bash --all-features ``` -------------------------------- ### Manually Add Rye Shims to PATH on Windows Source: https://github.com/astral-sh/rye/blob/main/docs/guide/installation.md Manually add the Rye shims directory to the system's PATH environment variable through the System Properties dialog. This is a fallback if the installer does not configure it automatically. ```powershell Note that you might need to restart your login session for this to take effect. ``` -------------------------------- ### Sync Virtual Environment with Rye Source: https://context7.com/astral-sh/rye/llms.txt Resolves and installs dependencies into the virtual environment based on lock files. Supports options to skip locking, include only production dependencies, update all or specific packages, and enable features. ```bash # Full sync: update lock files and virtualenv rye sync ``` ```bash # Sync without updating lock files (install from existing locks only) rye sync --no-lock ``` ```bash # Sync production dependencies only (skip dev dependencies) rye sync --no-dev ``` ```bash # Sync and update all dependencies to their latest compatible versions rye sync --update-all ``` ```bash # Sync and update a specific package rye sync --update flask ``` ```bash # Sync with optional feature dependencies enabled rye sync --features=web ``` ```bash # Sync a workspace package feature rye sync --features=my-package/feature-name ``` ```bash # Enable all optional features rye sync --all-features ``` ```bash # Include pre-release versions during resolution rye sync --pre ``` ```bash # Generate lock file with source references (useful for Docker, private indexes) rye sync --with-sources ``` -------------------------------- ### Define Rye Scripts with `cmd` Source: https://github.com/astral-sh/rye/blob/main/docs/guide/pyproject.md Use the `cmd` key to specify the command to execute for a script. This can be a string or an array of arguments. Shell interpolation is not available. ```toml [tool.rye.scripts] devserver = { cmd = "flask run --app ./hello.py --debug" } http = { cmd = ["python", "-mhttp.server", "8000"] } ``` -------------------------------- ### Add PyTorch Sources to Global Config Source: https://github.com/astral-sh/rye/blob/main/docs/guide/faq.md Configure PyTorch sources globally in your ~/.rye/config.toml file. ```toml [[sources]] name = "pytorch" url = "https://download.pytorch.org/whl/cpu" ``` -------------------------------- ### Sync Environment with uv sync Source: https://github.com/astral-sh/rye/blob/main/docs/guide/uv.md Synchronizes the project's environment based on the lockfile. Recommended for Docker build steps. ```bash uv sync ``` -------------------------------- ### Build PEP 508 Requirement String Source: https://github.com/astral-sh/rye/blob/main/docs/guide/commands/make-req.md Use this command to construct a PEP 508 requirement string from package name, git repository, and revision. The output is printed to stdout. ```bash $ rye make-req flask --git https://github.com/pallets/flask --rev 4df377cfbf flask @ git+https://github.com/pallets/flask@4df377cfbf ```