Reputation: 33
When importing evaluate in a notebook I get the following error.
import pandas as pd
import numpy as np
import torch
import evaluate
from datasets import Dataset
metric = evaluate.load("accuracy")
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[9], line 4
2 import numpy as np
3 import torch
----> 4 import evaluate
5 from datasets import Dataset
6 # accuracy - does it match or not?
ModuleNotFoundError: No module named 'evaluate'
I've used a standard installation from https://anaconda.org/conda-forge/r-evaluate
I'm running: anaconda3 Jupyter Notebook 6.4.12 Python 3.9.13
Running Jupyter notebook from conda and installed module evaluate from notebook terminal. when completed, install returns no errors.
when installing from anaconda prompt, I get,
(base) C:\Users\smitty>conda install -c "conda-forge/label/gcc7" r-evaluate
Collecting package metadata (current_repodata.json): done
Solving environment:
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
environment location: C:\Users\smitty\anaconda3
added / updated specs: - r-evaluate
The following packages will be downloaded:
package | build
---------------------------|-----------------
_anaconda_depends-2022.10 | py39_2 68 KB
anaconda-custom | py39_1 4 KB
ca-certificates-2018.10.15 | ha4d7672_0 170 KB conda-forge/label/gcc7
certifi-2022.12.7 | py39haa95532_0 149 KB
openssl-1.1.1t | h2bbff1b_0 5.5 MB
------------------------------------------------------------
Total: 5.9 MB
The following NEW packages will be INSTALLED:
_anaconda_depends pkgs/main/win-64::_anaconda_depends-2022.10-py39_2 pandas pkgs/main/win-64::pandas-1.4.4-py39hd77b12b_0
The following packages will be UPDATED:
certifi 2022.9.14-py39haa95532_0 --> 2022.12.7-py39haa95532_0 openssl 1.1.1q-h2bbff1b_0 --> 1.1.1t-h2bbff1b_0
The following packages will be SUPERSEDED by a higher-priority channel:
ca-certificates pkgs/main::ca-certificates-2022.07.19~ --> conda-forge/label/gcc7::ca-certificates-2018.10.15-ha4d7672_0
The following packages will be DOWNGRADED:
anaconda 2022.10-py39_0 --> custom-py39_1
Proceed ([y]/n)? y
Downloading and Extracting Packages
Preparing transaction: done Verifying transaction: done Executing transaction: done
(base) C:\Users\smitty>
after running conda list, i can see the package is in the list so not sure why I am getting this error
Upvotes: 1
Views: 5269
Reputation: 9909
Try running %pip install evaluate
inside your notebook, then restart the kernel, and then try the import evaluate
.
Conda has no recipe for HuggingFace's Python-based evaluate. The conda site you were pointing at is for a completely different evaluate based on R code. Specifically, you link to https://anaconda.org/conda-forge/r-evaluate. (That is why it is named r- evaluate. There's a whole series of libraries for the R language following that convention of being prefaced with 'r-'. Just like in the Python ecosystem you'll often see py prefixed to the start of package name.)
R code won't work inside your Python-based notebook, by default. And given the import evaluate
you are looking to use this code in Python. And so conda wasn't installing anything you needed when you were specifying 'r-evaluate
' by following the command shown at the conda-forge r-evaluate page, and your Python import
statement was subsequently failng. There is presently no choice but to use the evaluate that is at PyPI and for that you need to use pip
.
I understand that you are wary of using pip
and your instincts are right to stick with Anaconda/conda as much as you can for keeping your conda environments robust and portable since Anaconda/conda is your main package manager; however, there are certain packages that don't have Anaconda / conda recipes, and so you have to use pip
.
%pip install
magicIf you are curious about the magic %pip install
command that I suggest you use, see here. I suggest you continue to use that version of the pip install
command in the future when running installations from inside a Jupyter notebook file to insure that the installation occurs in the environment being used by the kernel underlying the active notebook. As detailed at the suggested resource), there is a related %conda install
command, too.
Often you'll see outdated suggestions of using an exclamation point in conjunction with those install commands. That can cause issues, see the second paragraph here for more about that, and so the magic install commands were added a few years ago to Jupyter (now this has been finally also updated in the Google Colab branch). Because automagics are often on by default in modern Jupyter you are actually better off using no symbol in conjunction with the install commands than using an exclamation point. Without a symbol, the magic version will get used behind-the-scenes. However, explicit is always best, and so I suggest keeping the %
symbol so that it is clear to you and others what is happening.
Upvotes: 2