How to install sklearn package in Jupyter Notebook in pycharm - python

I was receiving the following error. I have installed the package in the pycharm. Now the module is available in main.py file but the module is not available in jupyter notebook that I am using in pycharm.
When I run the cell I still get the following error in jupyter notebook but not in main.py file.
Please help me out!
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-7a030bc34e9f> in <module>
----> 1 from sklearn.cluster import KMeans
2 import numpy as np
3
4 from sklearn.cluster import KMeans
5 import numpy as np
ModuleNotFoundError: No module named 'sklearn'

Related

Regarding python Module in anaconda environment

I am very new to python and i am trying to follow the cs231n course by doing coding examples using python.
I created the virtual environment ,based on this tutorial http://cs231n.github.io/setup-instructions/
After that i changed the environment in anaconda navigator also as follows,
Still , when i try to import the relevent packages i am getting a error.
import random
import numpy as np
from cs231n.data_utils import load_CIFAR10
import matplotlib.pyplot as plt
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-19cb248684d4> in <module>
1 import random
2 import numpy as np
----> 3 from cs231n.data_utils import load_CIFAR10
4 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'cs231n'
Can anyone help me to figure this out ? I tried myself to fix this but i couldn't find a solution.
Thank you

Not able to import Localization library in python 3.7

I am trying to import Localization library in python 3.7 in Jupyter notebooks but everytime it shows this error:
ModuleNotFoundError
Traceback (most recent call last)
<ipython-input-6-ca0ae5a2ecfb> in <module>()
2 from skimage.measure import regionprops
3 import matplotlib.patches as patches
----> 4 import localization
~\Anaconda3\lib\site-packages\localization\__init__.py in <module>()
----> 1 from geoProject import *
ModuleNotFoundError: No module named 'geoProject'
I have no project named 'geoProject' either.
It is not your fault. geoProject seems to be another file in that project.
https://github.com/kamalshadi/Localization/blob/master/localization/geoProject.py
It is not being imported correctly inside the localization module at the __init__.py file

Numpy & Matplotlib suddenly cannot be imported in Atom although it works fine in the Terminal

I'm regularly importing Matplotlib Numpy PySide2 in Atom. They unexpectedly cannot be import for an unknown reason and then appear to be again re-importable, again unexplained.
When trying to import matplotlib with the following command
import matplotlib.pyplot as plt
This scripts runs without problems when I run in a Jupyter notebook or through the Terminal. But When trying to run on Hydrogen in Atom, I get the following error message:
File "<ipython-input-3-3dc8365ef973>", line 6
ModuleNotFoundError: No module named 'matplotlib.backends'; 'matplotlib' is not a package
^
SyntaxError: invalid syntax
I get the same error with Pyside2 when trying to run the line
from PySide2.QtWidgets import QApplication, QLabel
I get the error message
ModuleNotFoundError: No module named 'PySide2.QtWidgets'; 'PySide2' is not a package
Here is the path of python (after having typed which python in the Terminal): /anaconda3/bin/python
I checked that the matplotlib is installed by running the command conda list in the Terminal and got (among all the other packages) those lines:
matplotlib 2.1.2 py36h6d6146d_0
matplotlib 2.2.2 <pip>
PySide2 5.9.0a1.dev1525348214
I tried to run the following command in the Terminal but didn't solve the problem
sudo apt-get install python3-matplotlib
sudo pip3 install matplotlib
I had a similar issue with numpy when trying to import import numpy. Although import numpy was not a problem an hour ago, I get now the following error message (it seems it wants to connect to a previously used script in which numpy was used, to open numpy itself):
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-592c151f282b> in <module>()
1 # from numpy import genfromtxt as gft
----> 2 import numpy
~/Downloads/numpy.py in <module>()
----> 1 from numpy import genfromtxt
2 my_data = genfromtxt('/Users/mymac/Documents/PyQt/image_viewer/csv_file_generator/eggs.csv',
3 delimiter=',',
4 dtype=None,
5 encoding=None)
ImportError: cannot import name 'genfromtxt'
I had the same issue when tryin to import opencv2: I got the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import---------------------------
------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-8f6675581547> in <module>()
5 from PySide2.QtCore import *
6 from PySide2.QtGui import *
----> 7 import cv2
8 import numpy
9 import csv
ImportError: numpy.core.multiarray failed to import
I visited the following site which didn't help me (or I didn't understand how to implement exactly the steps to fix the problem)
ImportError: No module named matplotlib.pyplot
Importing matplotlib.pyplot in atom editor
matplotlib Error: No module named matplotlib even though it is installed
I'm running on/with
python 3.6.5
macOS 10.13.4
Atom 1.27.0 x64
Hydrogen 2.4.1

import error OpenCV on Jupyter Notebook (but it works in Ipython on Terminal..)

I'm having an interesting error where I could import cv2 in Ipython on Terminal but cannnot import the library on Jupyter notebook. I checked the kernel but I'm using the same kernel (Anaconda python2.7)
Would someone has any idea how to fix this?
Error:
ImportErrorTraceback (most recent call last)
<ipython-input-2-52da0154cfe4> in <module>()
----> 1 import cv2
2 import numpy as np
ImportError: No module named cv2
$import os
$os.sys.path
['',
'/Users/kn/anaconda2/envs/python2/lib/python27.zip',
'/Users/kn/anaconda2/envs/python2/lib/python2.7',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-darwin',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-mac',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-tk',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-old',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/lib-dynload',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/Sphinx-1.4.6-py2.7.egg',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/aeosa',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/setuptools-27.2.0-py2.7.egg',
'/Users/kn/anaconda2/envs/python2/lib/python2.7/site-packages/IPython/extensions',
'/Users/kn/.ipython']
$which python
/Users/kn/anaconda2/envs/python2/bin/python
Create a one-line opencv.pth file under /Users/kn/anaconda2/lib/python2.7/site-packages.
The content of that file is like:
/usr/local/opt/opencv3/lib/python2.7/site-packages
This will append the opencv3 path under all conda environments permanently. I think it's better than just make cv2 available for python2 environment.

Can't import matplotlib under Ipython notebook anaconda

I have downloaded and installed anaconda. But when I run jupyter notebook and import matplotlib , it doesn't work. Below are some commands
which -a python
/home/user/anaconda3/bin/python
/usr/bin/python
which -a jupyter
/home/user/anaconda3/bin/jupyter
I run the notebook as follows
jupyter notebook
I get the below error
ImportError Traceback (most recent call last)
<ipython-input-1-fe07c3ebfee7> in <module>()
2 # before proceeding further.
3 from __future__ import print_function
----> 4 import matplotlib.pyplot as plt
5 import numpy as np
6 import os
ImportError: No module named 'matplotlib'
Note when I run python through terminal I can import matplotlib , the problem only persist in the browser of ipython notebook after running jupyter.
It worked after changing /usr/local/share/jupyter/kernels/python3/kernel.json .
The path there was /usr/bin/python , changed it to anaconda one.

Categories

Resources