profanity-check icon indicating copy to clipboard operation
profanity-check copied to clipboard

Issue with joblib

Open o2ba opened this issue 4 years ago • 14 comments

Traceback (most recent call last):
  File "C:/Users/conta/PycharmProjects/Discord/bot.py", line 11, in <module>
    from profanity_check import predict, predict_prob
  File "C:\Users\conta\anaconda3\envs\Discordbot\lib\site-packages\profanity_check\__init__.py", line 1, in <module>
    from .profanity_check import predict, predict_prob
  File "C:\Users\conta\anaconda3\envs\Discordbot\lib\site-packages\profanity_check\profanity_check.py", line 3, in <module>
    from sklearn.externals import joblib
ImportError: cannot import name 'joblib' from 'sklearn.externals' (C:\Users\conta\anaconda3\envs\Discordbot\lib\site-packages\sklearn\externals\__init__.py)

I've been trying to fix this error for a bit now, tried up & downgrading. Probably a case of dependency hell, has anyone else experienced this before?

o2ba avatar May 20 '20 20:05 o2ba

Fix for anyone wondering: Downgrade your scikit-learn to 0.20.2 to fix this issue.

o2ba avatar May 20 '20 20:05 o2ba

scikit-learn 0.22.2.post1 is what worked for me.

MebinAbraham avatar May 24 '20 21:05 MebinAbraham

Whenever I try to use scikit-learn 0.20.2, it gets stuck at building when running the setup.py (Python 3.8)

workaddiction avatar May 26 '20 13:05 workaddiction

How can I run it on my local to fix the issue? I cloned the repo on my local, but I don't know what to do next. Can you help me?

ilhan-mstf avatar Jun 11 '20 09:06 ilhan-mstf

How can I run it on my local to fix the issue? I cloned the repo on my local, but I don't know what to do next. Can you help me?

Assuming you're using pip3 (pip may work as well):

pip3 uninstall scikit-learn
pip3 install scikit-learn==0.20.2

ccombsnbcu avatar Jul 02 '20 17:07 ccombsnbcu

Fix for anyone wondering: Downgrade your scikit-learn to 0.20.2 to fix this issue.

Not working for python3.8. py3.8 requires sklearn >= 0.22 .

rscarrera27 avatar Jul 03 '20 02:07 rscarrera27

joblib==0.14.1 scikit-learn==0.20.2

>>> vectorizer = joblib.load(pkg_resources.resource_filename('profanity_check', 'data/vectorizer.joblib'))

>>> model = joblib.load(pkg_resources.resource_filename('profanity_check', 'data/model.joblib'))

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/user/anaconda3/envs/project/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 605, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "/home/user/anaconda3/envs/project/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 529, in _unpickle
    obj = unpickler.load()
  File "/home/user/anaconda3/envs/project/lib/python3.7/pickle.py", line 1088, in load
    dispatch[key[0]](self)
KeyError: 0

While loading model KeyError pops.

What version of joblib is required to load the model ??

afghani-iitkgp avatar Aug 03 '20 12:08 afghani-iitkgp

Running Python 3.8.5 (OSX) Downgraded scikit-learn to 0.22.2 I'm getting a different error

>>> from profanity_check import predict
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/profanity_check/__init__.py", line 1, in <module>
    from .profanity_check import predict, predict_prob
  File "/usr/local/lib/python3.8/site-packages/profanity_check/profanity_check.py", line 3, in <module>
    from sklearn.externals import joblib
  File "/usr/local/lib/python3.8/site-packages/sklearn/__init__.py", line 64, in <module>
    from .base import clone
  File "/usr/local/lib/python3.8/site-packages/sklearn/base.py", line 13, in <module>
    from .utils.fixes import signature
  File "/usr/local/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 14, in <module>
    from . import _joblib
  File "/usr/local/lib/python3.8/site-packages/sklearn/utils/_joblib.py", line 22, in <module>
    from ..externals import joblib
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/__init__.py", line 119, in <module>
    from .parallel import Parallel
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/parallel.py", line 28, in <module>
    from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/_parallel_backends.py", line 22, in <module>
    from .executor import get_memmapping_executor
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/executor.py", line 14, in <module>
    from .externals.loky.reusable_executor import get_reusable_executor
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/externals/loky/__init__.py", line 12, in <module>
    from .backend.reduction import set_loky_pickler
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/externals/loky/backend/reduction.py", line 125, in <module>
    from sklearn.externals.joblib.externals import cloudpickle  # noqa: F401
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/__init__.py", line 3, in <module>
    from .cloudpickle import *
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py", line 167, in <module>
    _cell_set_template_code = _make_cell_set_template_code()
  File "/usr/local/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py", line 148, in _make_cell_set_template_code
    return types.CodeType(
TypeError: an integer is required (got type bytes)

Echooff3 avatar Aug 07 '20 17:08 Echooff3

Getting same error as @Echooff3 on python37 and scikit-learn==0.20.2

astherath avatar Aug 10 '20 02:08 astherath

I dont think the downgrade helps. Getting the same error

bhagyesh-p avatar Aug 30 '20 10:08 bhagyesh-p

A few months ago, I had this all working, but now I get the same error.

Ubuntu 20.04 Python 3.8.2 webvtt-py==0.4.5 scikit-learn==0.20.2 joblib==0.16.0

  File "/tmp/youtubeget/lib/python3.8/site-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py", line 148, in _make_cell_set_template_code
    return types.CodeType(
TypeError: an integer is required (got type bytes)

The problem is compatibility with Python 3.8. I tried Ubuntu 20.04's Python 2.7, but another module I need requires Python 3. Then I used a PPA to install Python 3.7, and it all works. Here's a script

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.7 python3.7-venv

VENVDIR=/tmp/venv/youtubeget
rm -rf $VENVDIR
python3.7 -m venv $VENVDIR
source $VENVDIR/bin/activate
python -m pip install profanity_check scikit-learn==0.20.2 joblib

az0 avatar Sep 07 '20 21:09 az0

scikit-learn 0.22.2.post1 is what worked for me.

it worked for me too, many thanks

hoai97nam avatar Oct 15 '20 04:10 hoai97nam

The solution to downgrade (@az0 ) worked for me, too. Using poetry, the relevant entry looks like (this installs joblib as a dependency automatically):

[tool.poetry.dependencies]
python = "3.7.9"
profanity-check = "1.0.3"
scikit-learn = "0.20.2"

However, I set this up using pyenv, without altering the system python. This worked quite well after initial confusions. It should work and integrate well with poetry, see here or here.

alexpovel avatar Nov 03 '20 16:11 alexpovel

Found this as an alternative:

https://pypi.org/project/alt-profanity-check/

Worked for me with Python 3.8

xhulianoThe1 avatar Mar 14 '21 00:03 xhulianoThe1