automl / auto-sklearn

Automated Machine Learning with scikit-learn
https://automl.github.io/auto-sklearn
BSD 3-Clause "New" or "Revised" License
7.58k stars 1.28k forks source link

How Do You Install Auto-sklearn in Google Colab? #1684

Open tron27 opened 1 year ago

tron27 commented 1 year ago

Hello all, This is from "Fails when installing via pip #1681 ! I read through this discussion and I'm still confused on how to install auto-sklearn in Google Colab. I've attempted to install auto-sklearn version 0.15.0.

I realized that this issue is closed, but I just came across it. I've been struggling with getting auto-sklearn to work properly for about 3 days now. I've downgraded my python version from 3.10.12 to 3.9.18 in Google Colab. Though, I was able to install auto-sklearn, I'm unable to import it or any of it's other functions such as classification. Attached is my Google Colab file (in pdf format). Any help is greatly appreciated. I've sincerely tried to figure this out, but it's above my capabilities at this point. Much of the code in this file came from stackoverflow. I understood it enough to use it.

Environment and installation: Details about my installation:

Ubuntu 22.04 - In Google Colab Python version 3.9.18 Auto-sklearn version

Code used in Google Colab (Also attached in a pdf file): !python --version # Python 3.10.12

install python 3.9

!sudo apt-get update -y !sudo apt-get install python3.9

change alternatives

!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1

check python version

!python --version # Python 3.9.18

install pip for new python

!sudo apt-get install python3.9-distutils !wget https://bootstrap.pypa.io/get-pip.py !python get-pip.py

credit of these last two commands belongs to @Erik

install colab's dependencies

!python -m pip install ipython ipython_genutils ipykernel jupyter_console prompt_toolkit httplib2 astor

link to the old google package

!ln -s /usr/local/lib/python3.9/dist-packages/google

See list of installed Python Versions

!sudo update-alternatives --config python3

install linux dependencies

!sudo apt-get install build-essential swig python3-dev !pip install auto-sklearn # This works!

import autosklearn

import autosklearn. # This does not work!

Auto-sklearn Install.ipynb - Colaboratory.pdf

anthonyromyn commented 1 year ago

Hey @tron27,

Yeah it drove me a bit nuts for a while too. I took bits and pieces from https://github.com/automl/auto-sklearn/issues/1675 and https://github.com/automl/auto-sklearn/issues/1681 and ultimately got it working like so (messy, silly, but working):

Working in Python 3.10.12,

Part 1:

Step 1. a first bit of package management:

!pip install Cython==0.29.36
!pip uninstall scipy -y
!pip install scipy==1.9
!pip uninstall pyparsing -y
!pip install pyparsing==2.4
!pip uninstall scikit_learn -y

Step 2. I install a few packages here I need for my analyses

Step 3. uninstall some more packages at this point i.e. that came with step 2) that conflict with the older scikitlearn I install at step 4.

!pip uninstall imbalanced-learn -y
!pip uninstall mlxtend -y
!pip uninstall yellowbrick -y

Step 4. install old scikit learn !pip install scikit-learn==0.24.2 --no-build-isolation

Step 5. install autoskl !pip install auto-sklearn

Part 2:

Step 6. try importing autoskl import autosklearn It should throw out an error [Errno 2] No such file or directory: '/usr/local/lib/python3.10/dist-packages/scipy-1.10.1.dist-info/METADATA'

rerun

!pip uninstall scipy -y
!pip install scipy==1.9

Step 7. try importing autoskl again import autosklearn now it should throw out the same error but for pyparsing [Errno 2] No such file or directory: '/usr/local/lib/python3.10/dist-packages/pyparsing-3.1.1.dist-info/METADATA'

rerun

!pip uninstall pyparsing -y
!pip install pyparsing==2.4

Step 8. try importing autoskl a third time import autosklearn Lastly it should throw out the same error but for scikitlearn [Errno 2] No such file or directory: '/usr/local/lib/python3.10/dist-packages/scikit_learn-1.2.2.dist-info/METADATA'

rerun

!pip uninstall scikit_learn -y
!pip install scikit-learn==0.24.2 --no-build-isolation

Step 9. now when you try importing autoskl again it will work fully!

import autosklearn
import autosklearn.classification as classifier
from autosklearn.metrics import (accuracy,
                                 f1,
                                 roc_auc,
                                 precision,
                                 average_precision,
                                 recall,
                                 log_loss)
import autosklearn.regression
tron27 commented 1 year ago

Anthony, Thank you for your help! I was able to get auto-sklearn installed. I followed your steps and it works. In fact, I was able to get auto-sklearn installed after Step 5. However, I went through all of the steps that you mentioned.

hjort commented 11 months ago

Based on @anthonyromyn 's post, I followed these steps:

# 1. uninstall all affected packages
!pip uninstall -y Cython scipy pyparsing scikit_learn imbalanced-learn mlxtend yellowbrick

# 2. install packages to be downgraded
!pip install Cython==0.29.36 scipy==1.9 pyparsing==2.4

# 3. install older scikit-learn disregarding its dependencies
!pip install scikit-learn==0.24.2 --no-build-isolation

# 4. finally install auto-sklearn
!pip install auto-sklearn

# 5. then, try loading the package repeatedly until trash in its dependencies are clean
import autosklearn

It's just a workaround. But it serves until the correction is done for Python 3.10.

by12380 commented 7 months ago

The following code from https://stackoverflow.com/questions/53839948/how-to-install-auto-sklearn-on-googlecolab worked for me

!sudo apt-get install build-essential swig
!curl https://raw.githubusercontent.com/automl/auto-sklearn/master/requirements.txt | xargs -n 1 -L 1 pip install
!pip install auto-sklearn
import autosklearn.classification
ststevanovic commented 6 months ago

Edit: Worked as suggested by others after many attempts. Worked only in case when I started from fresh new colab notebook.


In my case - Tried all of the above solutions, getting the same err mostly:

Collecting scikit-learn<0.25.0,>=0.24.0 (from auto-sklearn) Downloading scikit-learn-0.24.2.tar.gz (7.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.5/7.5 MB 39.3 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done error: subprocess-exited-with-error

× Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip. Preparing metadata (pyproject.toml) ... error error: metadata-generation-failed

I also tried solving the issue using condacolab... and the thing gets more descriptive imho:

... Setting up condacolab ...

Install auto-sklearn from the conda-forge channel

!mamba install -c conda-forge auto-sklearn scikit-learn python=3.9 # Tried it first with auto-sklearn only (py3.10) - similar output (see bellow) Looking for: ['auto-sklearn', 'scikit-learn', 'python=3.9']

conda-forge/linux-64 Using cache conda-forge/noarch Using cache

Pinned packages:

warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE Could not solve for environment specs The following packages are incompatible ├─ auto-sklearn is installable and it requires │ └─ scikit-learn >=0.24.0,<0.25.0 with the potential options │ ├─ scikit-learn [0.24.0|0.24.1|0.24.2] would require │ │ └─ python_abi 3.6 _pypy36_pp73, which can be installed; │ ├─ scikit-learn [0.24.0|0.24.1|0.24.2] would require │ │ └─ python_abi 3.6. _cp36m, which can be installed; │ ├─ scikit-learn [0.24.0|0.24.1|0.24.2] would require │ │ └─ python_abi 3.7. _cp37m, which can be installed; │ ├─ scikit-learn [0.24.0|0.24.1|0.24.2] would require │ │ └─ python_abi 3.8. _cp38, which can be installed; │ ├─ scikit-learn [0.24.0|0.24.1|0.24.2] would require │ │ └─ python_abi 3.9. _cp39, which can be installed; │ └─ scikit-learn [0.24.1|0.24.2] would require │ └─ python_abi 3.7 _pypy37_pp73, which can be installed; └─ python 3.9** is requested and can be installed.