【问题标题】:Import error on Google colab after pip install and restarting runtimepip安装并重新启动运行时后Google colab上的导入错误
【发布时间】:2020-10-29 09:41:16
【问题描述】:

我想在 Google Colab 上使用一个包 (resreg)。我将它安装在我的第一个单元中

!pip install resreg

我得到以下输出:

Collecting resreg
  Downloading https://files.pythonhosted.org/packages/61/74/0b664a8507e15507da5031fd92877d57551a7d362edc8089aa369c340e84/resreg-0.1-py3-none-any.whl
Collecting scikit-learn==0.21.0
  Downloading https://files.pythonhosted.org/packages/b7/6c/ec121123c671d980c6969dfc69d0f09e1d7f88d80d373f511e61d773b85c/scikit_learn-0.21.0-cp36-cp36m-manylinux1_x86_64.whl (6.6MB)
     |████████████████████████████████| 6.6MB 3.8MB/s 
Requirement already satisfied: scipy>=1.0.0 in /usr/local/lib/python3.6/dist-packages (from resreg) (1.4.1)
Requirement already satisfied: pandas>=0.24.0 in /usr/local/lib/python3.6/dist-packages (from resreg) (1.0.5)
Requirement already satisfied: numpy>=1.14.0 in /usr/local/lib/python3.6/dist-packages (from resreg) (1.18.5)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-learn==0.21.0->resreg) (0.15.1)
Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.24.0->resreg) (2.8.1)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.24.0->resreg) (2018.9)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.6.1->pandas>=0.24.0->resreg) (1.12.0)
Installing collected packages: scikit-learn, resreg
  Found existing installation: scikit-learn 0.22.2.post1
    Uninstalling scikit-learn-0.22.2.post1:
      Successfully uninstalled scikit-learn-0.22.2.post1
Successfully installed resreg-0.1 scikit-learn-0.21.0

然后我重新启动运行时使用 ">Runtime >Restart Runtime"

当我尝试导入包时,出现以下错误

from sklearn.linear_models import ElasticNet
import resreg
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-be63596e9fde> in <module>()
     1 from sklearn.linear_model import ElasticNet
---> 2 import resreg
ModuleNotFoundError: No module named 'resreg'

可能出了什么问题?

【问题讨论】:

    标签: python import scikit-learn pip google-colaboratory


    【解决方案1】:

    在不同的代码单元中尝试以下操作:

    [1]

    !git clone https://github.com/jafetgado/resreg.git
    !cd resreg
    

    [2]

    !pip install -e resreg
    

    [3]

    import resreg
    # ... Rest of your code goes here.
    

    如果它在第一次运行时不起作用,请在运行 [3] 之前尝试重新启动内核(转到运行时 -> 重新启动运行时)。

    安装 resreg 时值得注意的一点是,正如堆栈跟踪中所指出的,它依赖于 scikit-learn-0.21.0,因此您将无法使用 newest stable release 上提供的新功能(目前23.0) 和它的新功能。

     Installing collected packages: scikit-learn, resreg
      Found existing installation: scikit-learn 0.22.2.post1
        Uninstalling scikit-learn-0.22.2.post1:
          Successfully uninstalled scikit-learn-0.22.2.post1
      Running setup.py develop for resreg
    Successfully installed resreg scikit-learn-0.21.0
    

    【讨论】:

      猜你喜欢
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      相关资源
      最近更新 更多