Issue
I created a fresh conda environment for using scikit-learn and used
conda install <package>
to install scikit-learn
, jupyter
, pandas
, etc. for compatible dependencies..
I checked if sklearn
was working after loading the environment:
$python
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
>>>
Since import
command didn't throw errors, sklearn
is ready for use. However, I am getting a ModuleNotFoundError
while trying to import it in a jupyter notebook, that I am running from the same environment.
import sklearn
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>()
----> 1 import sklearn
ModuleNotFoundError: No module named 'sklearn'
I was able to import numpy
and pandas
in the same notebook without any errors.
Using packages in environments is new to me and I am learning from experience. Please help me understand the problem and how to troubleshoot it.
Solution
Best practice: Install everything via conda or pip3, as mentioned in this answer.
If that didn't work, check the system paths in jupyter notebook:
import sys
sys.path
and the system executable:
sys.executable
These must correspond to the python in your current loaded environment.
For me, the issue was with the jupyter Notebook's kernel. See the kernel specifications in kernel.json
file in the path. You can find the directory for this file from jupyter kernelspec list
. I manually changed the python path to the python in my environment (this is a bad idea, but it worked).
Answered By - nac001
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.