diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index aeb6e134..97eb4e83 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,7 +14,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 - + - name: Update packages run: | pip install -U pip wheel @@ -44,9 +44,9 @@ jobs: - name: Install Dependencies run: | - poetry install + poetry install -E tensorflow - - name: Test with pytest + - name: Test with pytest run: | poetry run python -m pip freeze poetry run python -m pytest -v --cov=scikeras --cov-report xml --color=yes @@ -119,11 +119,10 @@ jobs: - name: Install Dependencies run: | - poetry install - poetry add "tensorflow==${{matrix.tf-version}}" + poetry install -E tensorflow poetry add "scikit-learn==${{matrix.sklearn-version}}" - - name: Test with pytest + - name: Test with pytest run: | poetry run python -m pip freeze poetry run python -m pytest -v --cov=scikeras --cov-report xml --color=yes @@ -155,7 +154,7 @@ jobs: - name: Install Dependencies run: | - poetry install + poetry install -E tensorflow - name: Test with pytest run: | diff --git a/README.md b/README.md index 263c5eac..9d7b57b6 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,24 @@ An overview of the advantages and differences as compared to the TF wrappers can This package is available on PyPi: ```bash -pip install scikeras +# Normal tensorflow +pip install scikeras[tensorflow] + +# or tensorflow-cpu +pip install scikeras[tensorflow-cpu] ``` -The current version of SciKeras depends on `scikit-learn>=1.0.0` and `TensorFlow>=2.7.0`. +SciKeras packages TensorFlow as an optional dependency because there are +several flavors of TensorFlow available (`tensorflow`, `tensorflow-cpu`, etc.). +Depending on _one_ of them in particular disallows the usage of the other, which is why +they need to be optional. -You will need to manually install TensorFlow; due to TensorFlow's packaging it is not a direct dependency of SciKeras. -You can do this by running: +`pip install scikeras[tensorflow]` is basically equivalent to `pip install scikeras tensorflow` +and is offered just for convenience. You can also install just SciKeras with +`pip install scikera`s, but you will need a version of tensorflow installed at +runtime or SciKeras will throw an error when you try to import it. -```bash -pip install tensorflow -``` +The current version of SciKeras depends on `scikit-learn>=1.0.0` and `TensorFlow>=2.7.0`. ### Migrating from `tf.keras.wrappers.scikit_learn` diff --git a/docs/source/install.rst b/docs/source/install.rst index 24cc6628..f7e3f3c6 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -13,7 +13,7 @@ To install with pip, run: .. code:: bash - pip install scikeras + pip install scikeras[tensorflow] We recommend to use a virtual environment for this. diff --git a/docs/source/notebooks/Benchmarks.md b/docs/source/notebooks/Benchmarks.md index 831b8580..b22881c9 100644 --- a/docs/source/notebooks/Benchmarks.md +++ b/docs/source/notebooks/Benchmarks.md @@ -35,7 +35,7 @@ SciKeras wraps Keras Models, but does not alter their performance since all of t try: import scikeras except ImportError: - !python -m pip install scikeras + !python -m pip install scikeras[tensorflow] ``` Silence TensorFlow logging to keep output succinct. diff --git a/docs/source/notebooks/DataTransformers.md b/docs/source/notebooks/DataTransformers.md index d95a33f1..1291006c 100644 --- a/docs/source/notebooks/DataTransformers.md +++ b/docs/source/notebooks/DataTransformers.md @@ -50,7 +50,7 @@ In this notebook, we explore how to reconcile this functionality with the sklear try: import scikeras except ImportError: - !python -m pip install scikeras + !python -m pip install scikeras[tensorflow] ``` Silence TensorFlow warnings to keep output succint. diff --git a/docs/source/notebooks/Meta_Estimators.md b/docs/source/notebooks/Meta_Estimators.md index bb05578f..810dacf3 100644 --- a/docs/source/notebooks/Meta_Estimators.md +++ b/docs/source/notebooks/Meta_Estimators.md @@ -35,7 +35,7 @@ In this notebook, we implement sklearn ensemble and tree meta-estimators backed try: import scikeras except ImportError: - !python -m pip install scikeras + !python -m pip install scikeras[tensorflow] ``` Silence TensorFlow logging to keep output succinct. diff --git a/pyproject.toml b/pyproject.toml index ee5e01ef..a105178a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,12 @@ importlib-metadata = {version = "^3", python = "<3.8"} python = ">=3.7.0,<3.10.0" scikit-learn = ">=1.0.0" packaging = ">=0.21,<22.0" +tensorflow = {version = ">=2.7.0", optional = true} +tensorflow-cpu = {version = ">=2.7.0", optional = true} + +[tool.poetry.extras] +tensorflow = ["tensorflow"] +tensorflow-cpu = ["tensorflow-cpu"] [tool.poetry.dev-dependencies] tensorflow = ">=2.7.0"