Jython not finding virtualenv packages - python

When I do pip freeze I see numpy and sklearn in my virtualenv. When
My runner.py consists of :
from preprocess import Data
def main():
pass
preprocess.py
from sklearn.preprocessing import RobustScaler
import numpy as np
I run jython runner.py I get the error:
from sklearn.preprocessing import RobustScaler
ImportError: No module named sklearn
Not sure why I can't find any of the packages I've installed.

Related

Ipython seems installed but is showing as module not available

I am using Python 3.7.3 installed from Anaconda. It has installed Ipython: I can invoke Ipython from the command line and running the following code in Jupyter notebooks I can see the ipython as an installed package
import subprocess
import sys
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
installed_packages = [r.decode().split('==')[0] for r in reqs.split()]
print (installed_packages)
However in the same Jupyter notebook when I run the following code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pydotplus
from Ipython.display import Image
from sklearn.linear_model import LogisticRegression
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
from sklearn.decomposition import FactorAnalysis
from sklearn.cluster import KMeans
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix,accuracy_score,f1_score
I get the error returned : ModuleNotFoundError: No module named 'Ipython'
It's a Windows 10 machine. I tried reinstalling with conda install and conda update to no avail, and I tried variants of capitalisation.
You have a typo. The P in IPython is meant to be capitalized.
Use:
from IPython.display import Image

ModuleNotFoundError: No module named 'utils.datasets'

I am using Python 3.6.8 on Windows 10
I installed tensorflow, keras, and utils using pip.
pip install tensorflow and it installs the version 2.0.0
pip install keras and it installs the version 2.3.1
pip install utils but it does not show what version I have installed.
This is my header:
from keras.preprocessing import image
from PIL import Image
from keras.models import model_from_json, load_model
import numpy as np
import cv2
from datetime import datetime
import os
import random
import string
from utils.datasets import get_labels
from utils.inference import apply_offsets
from utils.inference import load_detection_model
from utils.preprocessor import preprocess_input
This is my error:
from utils.datasets import get_labels
ModuleNotFoundError: No module named 'utils.datasets'
Why am I getting this error? And how to fix it? BTW The code was written by a previous programmer and I need to modify it. But I can't even run it. not so good in python tho. i'm just getting started to it.
All my google search are all purple but I can't seem to find any solutions.
EDIT
The suggested answer (ImportError: No module named datasets) does not satisfy my needs. I am having trouble on utils module. because when I comment out the line from utils.datasets import get_labels
The error is on the next line:
ModuleNotFoundError: No module named 'utils.inference'
The utils model what the code your provided want to import is the part of the oarriaga/face_classification project.
The pip installed utils modul is quite different package, so you should not have installed via pip. Your code try to import moduls from this package, but it obviously has no such moduls. That is why the error messages.
So what you have to do is pip uninstall utils and then if your project directory structure is complete, the above code will import the face_classification package's moduls.

scikit-learn not importing in jupyter notebook

I installed scikit-learn both using pip and conda commandas. Whenever I check the package, it shows that it is already installed but, whenever I try import it, it shows error.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
%matplotlib inline
ERROR:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-33-82d3fc6531ea> in <module>
3 import matplotlib.pyplot as plt
4 import seaborn as sns
----> 5 from sklearn.model_selection import train_test_split
6 get_ipython().run_line_magic('matplotlib', 'inline')
ModuleNotFoundError: No module named 'sklearn'
I have tried reinstalling it multiple times but it shows the same error
Make sure that if you install the sklearn package in the python version that you are working. For suppose if your system has two versions of python installed in it like both python 2 and python 3 then you have installed sklearn package in python 2 and executing your code in python 3 or vice-versa.
I think you don't have latest version of sklearn because in old version of sklearn
below code was not working.
from sklearn.model_selection import train_test_split
Please update your sklearn by following command
conda update scikit-learn
I got the same error while installing these.
What you can do is install all the packages using the command
conda install pandas
and all other packages similarly or all in once
conda install pandas numpy matplotlib scikit-learn
in your project directory.
And now you can open your jupyter notbook using command
jupyter notebook
in the same environment or I should say same project directory.

trouble with imports from sklearn

I have sklearn installed and I can import sklearn I can also import comb. I import numpy, import scipy. But when I try:
from sklearn.model_selection import cross_validation
or
from sklearn import svm
I get a traceback:
File "...\Anaconda3\lib\site-packages\sklearn\model_selection\_split.py", line 25, in <module>
from scipy.misc import comb
ImportError: cannot import name 'comb'
Something may have gone wrong in your scipy installation. The issue can be solved by uninstalling and reinstalling the 2 libraries (scipy and sklearn).
Refer to this link

Implementing a tutorial for Tensorflow and SaaK Transform: Handwritten Digits Recognition

I am learning to work with Tensorflow. I have installed most of the libraries.
# load libs
import torch
import argparse
from torchvision import datasets, transforms
import matplotlib.pyplot as plt
import numpy as np
from data.datasets import MNIST
import torch.utils.data as data_utils
from sklearn.decomposition import PCA
import torch.nn.functional as F
from torch.autograd import Variable
But I am facing an error like this:
ImportError Traceback (most recent call last)
<ipython-input-8-257b7af364e1> in <module>()
5 import matplotlib.pyplot as plt
6 import numpy as np
----> 7 from data.datasets import MNIST
8 import torch.utils.data as data_utils
9 from sklearn.decomposition import PCA
ImportError: No module named data.datasets
I have installed the "dataset" library using the following command:
sudo -H pip install dataset
But I am still seeing this error. I am using python 2.7.
I am pretty new to python. Can anyone help me in identifying the missing thing. Thanks in advance.
The dataset directory is placed next to main.py, so probably when you tried sudo -H pip install dataset you actually installed a irrelevant package.
So uninstall the wrong package and it would work:
sudo -H pip uninstall dataset

Categories