Unable to import sklearn and statsmodels from Anaconda from windows 10 pro - python-3.x

I'm relatively new to python, so please excuse my ignorance on what could be a very easy fix. I am running python 3.6 through the Rodeo IDE, and it has been great, as it is similar to R-Studio (which I am very familiar with). As an aspiring data scientist, I am trying to learn how to fit regression and time series models to data, and all of the tutorials that I have found all say that I need various packages, all of which should be included in the Anaconda library. After downloading and re-downloading Python, Rodeo, and Anaconda, and trying various online fixes, I have been unable to successfully load the scikit-learn and the statsmodels modules.
#here is everything I have tried.
#using pip
! pip install 'statsmodels'
! pip install 'scikit-learn'
! pip install 'sklearn'
I don't get any errors here, and to be honest I'm kind of confused as to what this actually does, but I have seen many people online always suggest that this is a big problem when trying to import modules.
#using import
import sklearn
import statsmodels
from sklearn import datasets
import statsmodels.api as sm
all of the above give me the same error:
import statsmodels.api as sm
ImportError: No module named 'statsmodels'
ImportError: Traceback (most recent call last)
ipython-input-184-6030a6549dc0 in module()
----> 1 import statsmodels.api as sm
ImportError: No module named 'statsmodels'
I have tried to set my working directory to the Anaconda 3 file that has all of the packages and rerunning the above code with no success.
I'm thinking that the most likely problem has to do with my inexperience, and it is probably a simple fix. Is it possible that the IDE is bad or anaconda just doesn't like me?
So keeping all of the above in mind, the question is, how can I import these modules successfully so that I can access their functionality?

Option 1:
After installing packages with pip, try closing and reopening your IDE/Jupyter Notebook and try again.
This is a known bug that Jake VanderPlas outlined here
Option 2:
Don't put quotations around your pip messages.
!pip install -U statsmodels
!pip install scikit-learn
Option 3:
Also are you using Anaconda? If you are, you should already have scikit-learn. If you are trying inside Rodeo, I think you need to set your path inside Rodeo. Open Rodeo and set the Python Path to your fresh anaconda. See here

Related

Exception has occurred: ModuleNotFoundError No module named 'cv2'

I have code that requires: import cv2
but get the error message: Exception has occurred: ModuleNotFoundError
No module named 'cv2'
I have seen exactly the same question before, but all the suggestions fail. The question is 6 years old and hence am repeating it.
various failed suggestions:
conda install --channel https://conda.anaconda.org/menpo opencv3
conda install -c menpo opencv
I am using Windows 10 and have python 3.8.1 running.
I have removed cv2 from the code which works without error and resolves the issue.
The link here (at time of writing, version 4.1.2.3) describes the opencv-python package:
opencv-python link
With the following description of cv2 towards the bottom of the page:
It's easier for users to understand opencv-python than cv2 and it makes it easier to find the package with search engines. cv2 (old interface in old OpenCV versions was named as cv) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet. Changing the import name or behaviour would be also confusing to experienced users who are accustomed to the import cv2.

Import error, there is no module named numpy, but it says that it is installed?

So I trying to install and run from MSFT the cntk, you know, just for fun. Anyway, I keep getting this error which says:
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Now I have looked around here a little and I found a post saying that I needed to install the latest version of NumPy, but when I go to do that, I get back this:
Requirement already satisfied: NumPy in c:\users\username\appdata\local\continuum\anaconda3\envs\cntk-py34\lib\site-packages
SO I really have no idea what is going on here.
Anyway, thanks in advance.
Is your IDE linked to Anaconda env? If you open up the Anaconda prompt and import numpy do you get the same error?
You probably have an environment outside of Anaconda which does not have numpy installed.
In my case, I was executing [filename].py from the Anaconda prompt as I would a batch file and was getting this error. I confirmed numpy was install by executing pip list.
Funning python and passing the script file name as an argument, eg python [filename].py, correctly imported the numpy module and executed the script without error.

Implementing word2vec in python3 WITHOUT gensim

We're running into a lot of problems installing word2vec within python3. We just keep getting a standard error that python can't find the package it's looking for.
Competition-Repo/agents$ python3
Python 3.4.3 [GCC 4.8.4] on linux
import word2vec
Traceback (most recent call last):
File "", line 1, in ImportError: No module named 'word2vec'
Most everything I've found has either someone else's implementation of word2vec within python3, or is accessed through Gensim. The pip-install for python2 imports flawlessly, now we need to set up the same thing for python3.
Thanks!
-Ben
I just installed the product from Github site without incident on Python 3.4 but Win7Pro. It imports but who knows after that, right?
It comes with a setup.py. Being an inveterate experimenter I tried that, contrary to instructions. It failed.
At least this is easy to try, assuming you haven't already.
How exactly are you importing in python2?
With gensim, you can either import with -
from gensim.models import Word2Vec
or with -
from gensim.models import word2vec
The former is for the class Word2Vec and the latter for the module.
There is a tutorial here for getting started
The way we were able to install it was through:
sudo pip3 install cython
sudo pip3 install word2vec
Turned out to be a lot easier than I had thought..

Python ImportError no module named statistics after downloading

I'm trying to run my code and I don't know what specific package I need in order to get my import statement to work. Below is my header and I keep getting an error saying ImportError no module named statistics. I have looked at a bunch of different pages to see where I can download a solution, but I am trapped. I know my code works because I ran it on my schools lab. If anyone can help, that' be great!
Just note I am a beginner and am using Linux on my virtual machine with Python 2.7
import sys
import requests
import matplotlib.pyplot as plt
import statistics as stat
Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)
It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.
You need to be using python 3.4 to import statistics. Upgrade to the current version and you should have no problems.

Not able to import PolynomialFeatures, make_pipeline in Scikit-learn

I'm not able to import the following modules in an ipython notebook:
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
The following error pops up
ImportError: cannot import name PolynomialFeatures
The same error also appears for make_pipeline.
I'm a newbie in scikit-learn, please help out.
I'm using the miniconda installation of python and the version number for scikit-learn is 0.14.1.
Polynomial Features is included for next version of scikit-learn and is not available in 0.14.1. Please update to 0.15-git if you want to use it. The same holds for make pipeline.
To get the bleeding edge version:
git clone git://github.com/scikit-learn/scikit-learn.git
python setup.py build_ext --inplace
Please read: http://scikit-learn.org/stable/developers/index.html#git-repo
You have to check your current version of scikit:
import sklearn
print sklearn.__version__
if it is less than 0.15.0, then you have to upgrade it. In addition to an excellent answer of Abhishek, you can follow official installation process (which is described for various OS).
If you are using pyCharm, it can be done even simpler: File -> Settings -> Project Interpreter and then select your package and click upgrade
(I selected another one, be cause my scikitlearn is the newest)

Resources