Skip to content

Fix dependency resolution to prevent using global Python site-packages#3134

Merged
joeyballentine merged 2 commits intomainfrom
copilot/fix-dependency-resolution-issue
Oct 20, 2025
Merged

Fix dependency resolution to prevent using global Python site-packages#3134
joeyballentine merged 2 commits intomainfrom
copilot/fix-dependency-resolution-issue

Conversation

Copy link
Contributor

Copilot AI commented Oct 19, 2025

Problem

ChaiNNer was erroneously resolving dependencies from global Python site-packages (particularly user site-packages like C:\Users\...\AppData\Roaming\Python\Python311\site-packages on Windows or ~/.local/lib/python3.X/site-packages on Linux) instead of using its own isolated environment.

This caused pip to skip installing packages in chaiNNer's venv when they were already present in the user's global site-packages, leading to:

  • Missing packages in chaiNNer's venv (e.g., 52 packages installed instead of the expected 92)
  • Runtime import errors when chaiNNer tried to use supposedly installed packages
  • Dependency conflicts between global and chaiNNer's required versions

The issue was particularly problematic for portable installations where users had existing Python environments with different package versions.

Root Cause

Python by default enables user site-packages lookup (via site.ENABLE_USER_SITE), and subprocess environments inherited all environment variables from the parent process. When pip ran to install dependencies, it would:

  1. Find packages already installed in the user site-packages directory
  2. Skip installing them in chaiNNer's isolated venv
  3. Cause runtime errors because chaiNNer's Python instance couldn't access those global packages

Solution

Set the PYTHONNOUSERSITE=1 environment variable in all Python subprocess calls to disable Python's user site-packages lookup. This ensures pip only sees and uses packages from chaiNNer's isolated environment.

Changes

  1. src/main/env.ts - Added PYTHONNOUSERSITE=1 to the sanitizedEnv used by all backend processes
  2. backend/src/dependencies/store.py - Added PYTHONNOUSERSITE=1 to the ENV dictionary used by pip install/uninstall operations
  3. backend/src/dependencies/install_server_deps.py - Updated to import and use ENV from store.py for the pip list command

Testing

  • ✅ All JavaScript/TypeScript tests pass (96 tests)
  • ✅ All Python tests pass (9 tests)
  • ✅ Linters pass (eslint, stylelint, ruff)
  • ✅ CodeQL security scan - 0 alerts
  • ✅ Manual verification confirms PYTHONNOUSERSITE=1 correctly disables user site-packages

Impact

This fix ensures chaiNNer's portable installation will:

  • Never use packages from global user site-packages directories
  • Always install all required packages in its own isolated environment
  • Work correctly even if users have conflicting Python packages installed globally
  • Properly install all 92 required packages instead of only 52

Fixes #2962 (related issue)

Original prompt

This section details on the original issue you should resolve

<issue_title>chaiNNer erroneously resolves dependencies using global Python site-packages instead of its own environment</issue_title>
<issue_description><!--
Before you make open an issue, please search for your problem using the search bar here: https://github.com/chaiNNer-org/chaiNNer/issues

Many problems are reported to us multiple times, so please try to find your problem before opening a new issue.
-->

Information:

  • Chainner version: 0.24.1.zip [Portable]
  • OS: Windows 11 23H2

Description

Probably related #2962

Existing packages in C:\Users\zxc\AppData\Roaming\Python\Python311\site-packages are used when resolving dependencies and skipped when the program is first run. This causes errors at runtime where the program cannot find supposedly installed packages within the venv.

Repo steps for my configuration:

  1. Windows
  2. Prior 3.11 install, now 3.12.2
  3. Run chaiNNer with core dependencies existing in Python311\site-packages such as attr or multidict
  4. Observe broken chaiNNer blank screen when opening the program #2962
  5. Observe missing packages in chainner\python\python\Lib\site-packages

Solution for a working chaiNNer portable in my case was to merely rename the old site-packages folder until after initial setup. In the working chaiNNer chainner\python\python\Lib\site-packages I have 92 packages. The broken merely has 52.

Logs

main.log
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3010


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix chaiNNer dependency resolution using global site-packages Fix dependency resolution to prevent using global Python site-packages Oct 19, 2025
Copilot AI requested a review from joeyballentine October 19, 2025 05:58
Copilot AI and others added 2 commits October 19, 2025 14:48
Co-authored-by: joeyballentine <34788790+joeyballentine@users.noreply.github.com>
@joeyballentine joeyballentine force-pushed the copilot/fix-dependency-resolution-issue branch from bd66eb8 to 867e625 Compare October 19, 2025 19:48
@joeyballentine joeyballentine marked this pull request as ready for review October 20, 2025 05:43
@joeyballentine joeyballentine merged commit 30f851e into main Oct 20, 2025
17 checks passed
@joeyballentine joeyballentine deleted the copilot/fix-dependency-resolution-issue branch October 20, 2025 05:45
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.

chaiNNer erroneously resolves dependencies using global Python site-packages instead of its own environment blank screen when opening the program

2 participants