import nltk gives TypeError: an integer is required (got type bytes) when scikit-learn is installed
See original GitHub issueimporting nltk when scikit-learn (latest, 0.23.1 but also tried 0.21-2) is installed gives this:
root@55ee48c4633f:/home/project# python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/nltk/__init__.py", line 142, in <module>
from nltk.chunk import *
File "/usr/local/lib/python3.8/dist-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/usr/local/lib/python3.8/dist-packages/nltk/chunk/api.py", line 13, in <module>
from nltk.parse import ParserI
File "/usr/local/lib/python3.8/dist-packages/nltk/parse/__init__.py", line 100, in <module>
from nltk.parse.transitionparser import TransitionParser
File "/usr/local/lib/python3.8/dist-packages/nltk/parse/transitionparser.py", line 19, in <module>
from sklearn.datasets import load_svmlight_file
File "/usr/local/lib/python3.8/dist-packages/sklearn/__init__.py", line 80, in <module>
from .base import clone
File "/usr/local/lib/python3.8/dist-packages/sklearn/base.py", line 21, in <module>
from .utils import _IS_32BIT
File "/usr/local/lib/python3.8/dist-packages/sklearn/utils/__init__.py", line 23, in <module>
from .class_weight import compute_class_weight, compute_sample_weight
File "/usr/local/lib/python3.8/dist-packages/sklearn/utils/class_weight.py", line 7, in <module>
from .validation import _deprecate_positional_args
File "/usr/local/lib/python3.8/dist-packages/sklearn/utils/validation.py", line 22, in <module>
import joblib
File "/usr/local/lib/python3.8/dist-packages/joblib/__init__.py", line 119, in <module>
from .parallel import Parallel
File "/usr/local/lib/python3.8/dist-packages/joblib/parallel.py", line 28, in <module>
from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
File "/usr/local/lib/python3.8/dist-packages/joblib/_parallel_backends.py", line 22, in <module>
from .executor import get_memmapping_executor
File "/usr/local/lib/python3.8/dist-packages/joblib/executor.py", line 14, in <module>
from .externals.loky.reusable_executor import get_reusable_executor
File "/usr/local/lib/python3.8/dist-packages/joblib/externals/loky/__init__.py", line 12, in <module>
from .backend.reduction import set_loky_pickler
File "/usr/local/lib/python3.8/dist-packages/joblib/externals/loky/backend/reduction.py", line 125, in <module>
from joblib.externals import cloudpickle # noqa: F401
File "/usr/local/lib/python3.8/dist-packages/joblib/externals/cloudpickle/__init__.py", line 3, in <module>
from .cloudpickle import *
File "/usr/local/lib/python3.8/dist-packages/joblib/externals/cloudpickle/cloudpickle.py", line 152, in <module>
_cell_set_template_code = _make_cell_set_template_code()
File "/usr/local/lib/python3.8/dist-packages/joblib/externals/cloudpickle/cloudpickle.py", line 133, in _make_cell_set_template_code
return types.CodeType(
TypeError: an integer is required (got type bytes)
Steps to reproduce: Docker:
FROM ubuntu:latest
WORKDIR /home/project
RUN apt update && apt-get install -y python3 python3-pip build-essential
RUN pip3 install Cython && pip3 install -r requirements.txt && pip3 uninstall scikit-learn
then run
sudo docker run -it docker_image_name /bin/bash python3
then simply do
import nltk
to get import error ... TypeError: an integer is required (got type bytes)
Simply do pip3 uninstall scikit-learn
fix the error
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
an integer is required (got type bytes) when importing sklearn ...
I was able to reproduce the problem in a conda environment by running conda install python==3.8 scikit-learn but then manually downgrading ...
Read more >Fix - TypeError: an integer is required (got type bytes) - Kontext
When running PySpark 2.4.8 script in Python 3.8 environment with Anaconda, the following issue occurs: TypeError: an integer is required (got ...
Read more >python3.8使用scikit-learn0.20.2时报错TypeError: an integer is ...
解决过程:. 于是,我将scikit-learn降级为0.20.2版本,结果依然报错:TypeError: an integer is required (got type bytes) ...
Read more >Need help with this python import error. - Databricks Community
TypeError : an integer is required (got type bytes).
Read more >6.2. Feature extraction — scikit-learn 1.2.0 documentation
from sklearn.feature_extraction import DictVectorizer >>> vec ... In order to address this, scikit-learn provides utilities for the most common ways to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a lot @lucaszanella. Indeed
joblib==0.13.2
is not compatible withPython 3.8
. You need to usejoblib==0.14
or a later version. See joblib/joblib#888.Also the docker container should not uninstall scikit-learn to reproduce the error: