【问题标题】:Cannot import category_encoders module无法导入 category_encoders 模块
【发布时间】:2019-06-13 09:52:45
【问题描述】:

我无法在 python 3 虚拟环境中的 jupyter notebook 中导入 category_encoders 模块。

错误

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-15-86725efc8d1e> in <module>()
      9 from plotly import graph_objs
     10 from datetime import datetime
---> 11 import category_encoders as ce
     12 
     13 import sklearn

ModuleNotFoundError: No module named 'category_encoders'

“哪个点”的输出

/opt/virtual_env/py3/bin/pip

“pip show category_encoders”的输出是

Name: category-encoders
Version: 1.3.0
Summary: A collection sklearn transformers to encode categorical variables as numeric
Home-page: https://github.com/wdm0006/categorical_encoding
Author: Will McGinnis
Author-email: will@pedalwrencher.com
License: BSD
Location: /opt/virtual_env/py3/lib/python3.6/site-packages
Requires: numpy, pandas, statsmodels, scikit-learn, patsy, scipy
Required-by: 

“点子列表”的输出

Package             Version
------------------- -------
absl-py             0.7.0  
astor               0.7.1  
backcall            0.1.0  
category-encoders   1.3.0  
cycler              0.10.0 

【问题讨论】:

  • 如果您使用 anaconda,请使用 conda install category-encoders 安装软件包。重启jupyter。然后试试代码。
  • 我现在没有使用 anaconda。
  • 请重启jupyter并尝试执行。大多数时候,它会解决问题。
  • 我安装了内核,重启了很多次,还是这个错误。我确定我已经安装了 pip 和 scikit。我正在使用 pycharm。

标签: python encoding data-science categorical-data


【解决方案1】:

pip install --upgrade category_encoders

现在, 重启你的内核

import category_encoders as... 以此类推

另外, 您可以查看 sk-learn 的预处理类 CategoricalEncoder...

from sklearn.preprocessing import CategoricalEncoder

从这里获取 sk-learn,

pip install git+git://github.com/scikit-learn/scikit-learn.git

或简单

pip install sklearn

【讨论】:

    【解决方案2】:

    如果您已授予您的虚拟环境(您的情况为“py3”)访问系统站点包目录的权限,您可以尝试将包安装到您的基本(根)环境。

    在您的系统中搜索“pyvenv.cfg”文件并检查它是否包含:

    include-system-site-packages = true
    

    如果是,请按照here 的说明将包安装到您的根环境,然后尝试在您的 Jupyter Notebook 中再次导入它。

    【讨论】:

      【解决方案3】:

      我使用的是anaconda环境。

      最初,我使用 pip(在 conda 环境中)安装了category_encoders,但它未能解决。然后我从 pip 卸载了“category_encoders”

      pip uninstall category-encoders

      并使用 conda 安装它:

      conda install -c conda-forge category_encoders

      这解决了问题。

      【讨论】:

        【解决方案4】:

        您可以在上面添加一个单元格并输入! pip install --upgrade category_encoders

        它将在不打开终端窗口的情况下安装包。

        【讨论】:

          猜你喜欢
          • 2012-11-06
          • 2022-11-09
          • 2017-11-11
          • 2021-07-27
          • 2020-12-15
          • 2020-08-28
          • 2015-10-04
          • 2021-06-06
          相关资源
          最近更新 更多