A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
added python executable to pip and uv (#2478)
Alexander Kislukhina0f04153dd4f
diff --git a/marimo/_runtime/packages/pypi_package_manager.py b/marimo/_runtime/packages/pypi_package_manager.pyindex 269541b7ae..cf791c7469 100644--- a/marimo/_runtime/packages/pypi_package_manager.py+++ b/marimo/_runtime/packages/pypi_package_manager.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport jsonimport subprocess+import sysfrom typing import Listfrom marimo._runtime.packages.module_name_to_pypi_name import (@@ -15,6 +16,8 @@ from marimo._runtime.packages.package_manager import (from marimo._runtime.packages.utils import split_packagesfrom marimo._utils.platform import is_pyodide+PY_EXE = sys.executable+class PypiPackageManager(CanonicalizingPackageManager):def _construct_module_name_mapping(self) -> dict[str, str]:@@ -43,13 +46,24 @@ class PipPackageManager(PypiPackageManager):docs_url = "https://pip.pypa.io/"async def _install(self, package: str) -> bool:- return self.run(["pip", "install", *split_packages(package)])+ return self.run(+ ["pip", "--python", PY_EXE, "install", *split_packages(package)]+ )async def uninstall(self, package: str) -> bool:- return self.run(["pip", "uninstall", "-y", *split_packages(package)])+ return self.run(+ [+ "pip",+ "--python",+ PY_EXE,+ "uninstall",+ "-y",+ *split_packages(package),+ ]+ )def list_packages(self) -> List[PackageDescription]:- cmd = ["pip", "list", "--format=json"]+ cmd = ["pip", "--python", PY_EXE, "list", "--format=json"]return self._list_packages_from_cmd(cmd)@@ -103,7 +117,9 @@ class UvPackageManager(PypiPackageManager):docs_url = "https://docs.astral.sh/uv/"async def _install(self, package: str) -> bool:- return self.run(["uv", "pip", "install", *split_packages(package)])+ return self.run(+ ["uv", "pip", "install", *split_packages(package), "-p", PY_EXE]+ )def update_notebook_script_metadata(self,@@ -159,10 +175,12 @@ class UvPackageManager(PypiPackageManager):return {pkg.name: pkg.version for pkg in packages}async def uninstall(self, package: str) -> bool:- return self.run(["uv", "pip", "uninstall", *split_packages(package)])+ return self.run(+ ["uv", "pip", "uninstall", *split_packages(package), "-p", PY_EXE]+ )def list_packages(self) -> List[PackageDescription]:- cmd = ["uv", "pip", "list", "--format=json"]+ cmd = ["uv", "pip", "list", "--format=json", "-p", PY_EXE]return self._list_packages_from_cmd(cmd)diff --git a/tests/_runtime/packages/test_pypi_package_manager.py b/tests/_runtime/packages/test_pypi_package_manager.pyindex f40fa4f3d0..62730bb813 100644--- a/tests/_runtime/packages/test_pypi_package_manager.py+++ b/tests/_runtime/packages/test_pypi_package_manager.py@@ -1,6 +1,7 @@from __future__ import annotationsimport json+import sysfrom functools import partialfrom unittest.mock import MagicMock, patch@@ -12,6 +13,8 @@ from marimo._runtime.packages.pypi_package_manager import (parse_cell = partial(compiler.compile_cell, cell_id="0")+PY_EXE = sys.executable+def test_module_to_package() -> None:mgr = PipPackageManager()@@ -43,7 +46,7 @@ async def test_install(mock_run: MagicMock):result = await manager._install("package1 package2")mock_run.assert_called_once_with(- ["pip", "install", "package1", "package2"],+ ["pip", "--python", PY_EXE, "install", "package1", "package2"],)assert result is True@@ -64,7 +67,15 @@ async def test_uninstall(mock_run: MagicMock):result = await manager.uninstall("package1 package2")mock_run.assert_called_once_with(- ["pip", "uninstall", "-y", "package1", "package2"],+ [+ "pip",+ "--python",+ PY_EXE,+ "uninstall",+ "-y",+ "package1",+ "package2",+ ],)assert result is True@@ -82,7 +93,9 @@ def test_list_packages(mock_run: MagicMock):packages = manager.list_packages()mock_run.assert_called_once_with(- ["pip", "list", "--format=json"], capture_output=True, text=True+ ["pip", "--python", PY_EXE, "list", "--format=json"],+ capture_output=True,+ text=True,)assert len(packages) == 2assert packages[0] == PackageDescription(name="package1", version="1.0.0")