Skip to content

Fix COBRA install: add scikit-learn dependency + revamp install docs (#391)#392

Open
marouenbg wants to merge 2 commits into
netZoo:develfrom
marouenbg:fix/cobra-sklearn-dep-391
Open

Fix COBRA install: add scikit-learn dependency + revamp install docs (#391)#392
marouenbg wants to merge 2 commits into
netZoo:develfrom
marouenbg:fix/cobra-sklearn-dep-391

Conversation

@marouenbg

@marouenbg marouenbg commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #391.

Problem

A user following the documented install (git clonecd netZooPypip3 install -e .) could not run COBRA.

netZooPy/cobra/cobra.py imports from sklearn.linear_model import LinearRegression, Lasso, but setup.py did not list scikit-learn in install_requires (it was only in requirements.txt). Because netZooPy/__init__.py eagerly runs from netZooPy import cobra, a clean pip install -e . left import netZooPy itself broken with ModuleNotFoundError: No module named 'sklearn', not just COBRA.

Separately, the reporter's No module named 'netZooPy.cobra' / (unknown location) errors come from an environment pitfall: running Python from the clone's parent directory (or a Jupyter/VS Code kernel that isn't the install env) makes the cloned netZooPy folder resolve as an empty namespace package that shadows the installed one.

Changes

  • setup.py: add scikit-learn to install_requires (the substantive fix).
  • README.md: keep it minimal — only adds from netZooPy.cobra import cobra to the usage example.
  • docs/install/index.md: revamp the install guide —
    • sync the dependency list with setup.py (was missing h5py, joblib, statsmodels, scikit-learn, click, tables, torch) and note pip installs them automatically; document CuPy as the optional GPU dependency;
    • recommend a virtual environment;
    • expand the Troubleshooting section to cover both failure modes above.

Troubleshooting content lives in the install guide (where users look) rather than the README.

Verification

  • Clean python -m venv + pip install -e . now auto-installs scikit-learn; import netZooPy and from netZooPy.cobra import cobra both succeed; cobra() runs in nnls and MLE modes.
  • tests/test_cobra.py passes.
  • Audited every submodule's module-load-time imports: scikit-learn was the only undeclared hard dependency. cupy is correctly optional (lazy, GPU-only); patsy is guaranteed via statsmodels.

🤖 Generated with Claude Code

@marouenbg marouenbg closed this Jun 10, 2026
@marouenbg marouenbg reopened this Jun 10, 2026
netZooPy/cobra/cobra.py imports `from sklearn.linear_model import ...`,
but setup.py omitted scikit-learn from install_requires (it was only in
requirements.txt). Because netZooPy/__init__.py eagerly runs
`from netZooPy import cobra`, a fresh `pip install -e .` left not just
COBRA but `import netZooPy` itself broken with
`ModuleNotFoundError: No module named 'sklearn'`.

Also show the COBRA import in the README usage example.

Fixes netZoo#391

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@marouenbg marouenbg force-pushed the fix/cobra-sklearn-dep-391 branch from 090bd20 to c594c0a Compare June 10, 2026 21:39
@marouenbg marouenbg changed the title Fix COBRA import: add scikit-learn dependency + document import shadowing (#391) Add scikit-learn to install_requires (#391) Jun 10, 2026
…#391)

- Update the dependency list to match setup.py install_requires (adds
  h5py, joblib, statsmodels, scikit-learn, click, tables, torch) and note
  that pip installs them automatically; document CuPy as the optional GPU
  dependency.
- Recommend installing inside a virtual environment.
- Expand the Troubleshooting section with the two failure modes behind
  issue netZoo#391: the namespace-shadowing import error (running from the
  clone's parent / wrong kernel) and the missing-scikit-learn error.

Keeps the README minimal; troubleshooting lives in the install guide.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@marouenbg marouenbg changed the title Add scikit-learn to install_requires (#391) Fix COBRA install: add scikit-learn dependency + revamp install docs (#391) Jun 10, 2026
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