Skip to content

fix(postinstall): add venv creation fallback for Debian/Ubuntu#2

Open
lixiao888 wants to merge 1 commit into
konbakuyomu:mainfrom
lixiao888:fix/postinstall-venv-fallback
Open

fix(postinstall): add venv creation fallback for Debian/Ubuntu#2
lixiao888 wants to merge 1 commit into
konbakuyomu:mainfrom
lixiao888:fix/postinstall-venv-fallback

Conversation

@lixiao888
Copy link
Copy Markdown

Problem

npm install -g @konbakuyomu/smart-search@latest fails on Debian/Ubuntu systems with:

The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

Root cause: The postinstall.js script uses python3 -m venv which requires the ensurepip module. On Debian/Ubuntu, python3-venv is not installed by default, so ensurepip is missing.

Fix

Add a three-strategy fallback chain for venv creation:

  1. python3 -m venv — original behavior, works when python3-venv is installed
  2. virtualenv — install via pip install --user virtualenv if missing, then use it (bundles pip independently, no ensurepip needed)
  3. venv --without-pip + get-pip.py — create venv without pip, then bootstrap pip by downloading get-pip.py from bootstrap.pypa.io

Each strategy is tried in order; on failure, the partial venv is cleaned up before trying the next. If all strategies fail, a clear error message directs the user to install python3-venv.

Testing

Verified on a Debian system without python3-venv:

  • Strategy 1 fails (as expected, ensurepip missing)
  • Strategy 2 skipped (virtualenv not installed)
  • Strategy 3 succeeds: venv --without-pip + get-pip.py creates a working venv with pip

Changes

  • npm/scripts/postinstall.js: Extract venv creation into createVenv() with three fallback strategies; wrap main logic in async main() to support get-pip.py download; improve error messages for Debian/Ubuntu users.

On Debian/Ubuntu systems, python3-venv is not installed by default,
causing 'python3 -m venv' to fail due to missing ensurepip module.
This makes 'npm install -g @konbakuyomu/smart-search@latest' fail
with: 'ensurepip is not available'.

Add a three-strategy fallback chain:
1. python3 -m venv (original, works when python3-venv is installed)
2. virtualenv via pip --user (bundles pip independently)
3. venv --without-pip + get-pip.py bootstrap (no ensurepip needed)

Fixes the installation failure on Debian/Ubuntu without python3-venv.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant