How do I fix the issue "ModuleNotFoundError: No module named 'sklearn' - python

I'm using a Mac. I have Anaconda installed. When I type import numpy or import matplotlib I don't run into any issues. The only issue I'm having is with sklearn.
I'm fairly new to CS/ DS. Any help/ tips is greatly appreciated.
I've tried uninstalling sklearn and reinstalling. I've pretty much tried every solution on StackOverflow. The only thing I haven't tried is reinstalling anaconda.
import sklearn
Traceback (most recent call last):
File "", line 1, in
import sklearn
ModuleNotFoundError: No module named 'sklearn'
I expect to get no result just like with matplotlib and numpy which means everything works, but in lieu of that I get that output.

Do you have sklearn installed? It should be in some requirement, but it seems that someone needs it as a dependency and does not find it.
pip freeze | grep sklearn
It will tell you if you have it installed.
Do you work in a virtualenv?
If you do not have it installed try to do it and if not, pass the traceback.
if you work on mac you can also try updating xcode and updating yourself pip
xcode-select --install
pip install --upgrade pip

Related

MacOS Catalina, pip has installed packages but python cannot find them?

My pip has worked fine with my python 3 in the past and I have downloaded things such as pandas which all work fine in python. The problem I now encounter is any library I attempt to download using pip is not recognised by python. Here is how I have tried downloading skl.
pip install sklearn
pip3 install sklearn
When I input
pip list
or
pip3 list
Both list sklearn as being downloaded, however, when I go in python and input:
from sklearn import linear_model
I get the error
Traceback (most recent call last):
File "/Users/nicross/Desktop/RainDance/RainFaller.py",line 8, in <module>
from sklearn import linear_model
ModuleNotFoundError: No module named 'sklearn'
Any help solving this would be greatly appreciated.
python3 -m pip install sklearn
From the sklearn docs it looks like you might want to try:
pip install -U scikit-learn
(For more, try following the steps here: https://scikit-learn.org/stable/install.html and see if those fix it)

No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package

Everything was working smoothly until I started getting the following error:
Traceback (most recent call last):
File "", line 1, in
File "/home/user/Workspace/Practices/Tensorflow/tensorflow2/venv/lib/python3.7/site-packages/tensorflow/init.py", line 98, in
from tensorflow_core import *
File "/home/user/Workspace/Practices/Tensorflow/tensorflow2/venv/lib/python3.7/site-packages/tensorflow_core/init.py", line 40, in
from tensorflow.python.tools import module_util as _modle_util
ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package
My environment setup:
python-3.7
Using venv module to create virtual environment
tensorflow 2.0.0
pip 19.0.3
Manjaro Linux
Now, I even can't import tensorflow module as well. It gives same above error. Tried reinstalling with cache and without cache as well, but no luck. Recreated virtual environment as well, no luck. This is really weird and have no clue where to start troubleshooting as well. Looking at virtual environment site packages, everything seems fine.
I just faced this problem right now. I ran the source code on another computer and it showed the same error. I went ahead and compared the version of TensorFlow and turns out that the other computer was running tensorflow==2.1.0 and mine was running tensorflow==1.14.0.
In short, downgrade your tensorflow installation (pip install tensorflow==1.14.0)
Found a noob problem. I was using my file name as csv.py which already exist in python library, which I think was messing up the paths. But don't know how yet.
Try uninstalling and reinstalling. First run:
pip uninstall tensorflow
then reinstall:
pip install tensorflow==2.0
After you uninstall, in the python shell, run:
help('modules')
TensorFlow should not be there in that list. Only then proceed to install it.
You don't need to uninstall tensorflow what version you have because it will take time to reinstall. You can fix this issue just by installing tensorflow==2.0.
pip install tensorflow==2.0

ModuleNotFoundError Despite being Installed

I'm having trouble loading a package that is installed in my environment and have no idea why..
conda list
fbprophet 0.3.post2 py36_0 conda-forge
When I request for libraries installed in conda, it clearly shows that I have fbprophet installed. Now, when I import it, a ModuleNotFoundError exception is thrown.
from fbprophet import Prophet
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-83be6864a7aa> in <module>()
----> 1 from fbprophet import Prophet
2 import numpy as np
3 import pandas as pd
ModuleNotFoundError: No module named 'fbprophet'
Has anybody run into this issue? What can I do to troubleshoot this?
My suggestion would be creating a virtual environment for your python first, then conda install your package in the virtual environment.
My script was reading from my pip install list where the module fbprophet did not exist. I went back and installed it there and everything worked. Lesson learned.
Always check where your libraries are being read from.
You may have more than one Python installation. Thus you might installed the library in one Python installation and tried to call it from another one. Please let me know if you have more than one Python installation by printing the result os this CMD command where python.

ImportError: Missing required dependencies ['numpy']

I was able to run all scripts successfully which is using pandas , but suddenly all my PANDAS SCRIPTS are giving this error :
Traceback (most recent call last):
File "data_visulaization.py", line 5, in
import pandas as pd
File "/usr/lib64/python2.7/site-packages/pandas/init.py", line 18,
in
raise ImportError("Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Recently i have not installed or updated any new things.
Does anyone have a solution for this?
I uninstalled pandas and numpy and re-installed them but still facing the same issue.
I got this issue on Rasberry PI and found that the root cause was missing library:
import numpy
...
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
Then it takes few minute to google the required library source:
sudo apt-get install libatlas-base-dev
I have not checked the solution on any other Linux-es but likely the same method should be applicable. So try to import the faulty library first and see what is missing.
I faced the exact same error and found that I had created a file named 'random.pyc' by mistake in the same directory as that of my PyCharm environment
ayush#ayush-VirtualBox:~/PycharmProjects/untitled$ where "untitled" refers to my project directory. I deleted it and everything fells into place. Hope this helps !
The reason for this was numpy Imports another file called Random by default for building its own dependencies and it mistook my 'random.pyc' for it and replaced it.
I had the same error. Fixed with the following:
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
use"conda install numpy" in cmd-window if you used Anaconda in your machine. I had encount this problem also and I resolved it by this. May it can help U.
I found the solution , the actual problem is if any of your recent python scripts have generated ".pyc" extension file this error will occur .
solution is to delete those files that's all.
If you are using packages options and it contains pandas or some package depends numpy, you should add required dependencies to the packages.
pip uninstall numpy
pip install numpy
It works
This error will occur when multiple versions of numpy are installed. Check to make sure you only have one version of numpy installed. You can make a test file to check this if you don't want to look through the directories:
import numpy
print("Numpy imported")
If you get an error saying that multiple versions of numpy were detected, then you have multiple versions of numpy installed.
You can fix this by repeatedly calling (not just once)
pip uninstall numpy
until all versions are uninstalled and then use
pip install numpy
to get only the latest version.
try uninstalling pandas and numpy:
pip uninstall pandas
pip uninstall numpy
and install them back:
pip install pandas
pip install numpy

cv2 import error with caffe python

I'm trying to write my own python layer in caffe, and when I try to compile it, I keep getting this import error.
Traceback (most recent call last):
File "/home/username/caffe/layer_example.py", line 3, in <module>
import cv2
ImportError: /home/username/anaconda2/lib/python2.7/site-packages/cv2.so:undefined symbol: _ZN2cv11arrowedLineERNS_3MatENS_6Point_IiEES3_RKNS_7Scalar_IdEEiiid
I've tried to find a solution online, and changed my ~/.bashrc to look like this:
export PYTHONPATH=/home/username/caffe/python:/home/username/anaconda2/lib:$PYTHONPATH
I'm still getting the import error though. Any ideas on what the possible solution might be?
EDIT: Fixed the issue!
I uninstalled opencv(2.4.10) on conda, and installed version 2.4.9:
conda install opencv=2.4.9
conda install numpy
That fixed the error for me.
EDIT: Fixed the issue! I uninstalled opencv(2.4.10) on conda, and installed version 2.4.9:
conda install opencv=2.4.9
conda install numpy
That fixed the error for me.
sudo apt-get install python-opencv
could also be a solution.
Cuz caffe ubuntu installation guide install says you have to install
libopencv-dev
However, I observed that this package makes opencv only accessible to c++.
To use opencv with python I had to install python-opencv
I got this answer from Installing OpenCV for Python on Ubuntu, getting ImportError: No module named cv2.cv

Categories

Resources