Python Forum

Full Version: sklearn imported but not recognized
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Python forum,
I am a new learner and am following basic tutorials from udacity and youtube.
I am on python 2.7. I am using visual studio as an IDE.
I have imported sklearn and can see it under my file C/python27/Lib/Sitepackages folder.
when i type import.sklearn the ide autocompletes
but when i try to call the library I get:

Error:
>>> import sklearn Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "C:\Python27\lib\site-packages\sklearn\__init__.py", line 57, in <module>    from .base import clone  File "C:\Python27\lib\site-packages\sklearn\base.py", line 10, in <module>    from scipy import sparse ImportError: No module named scipy >>> sklearn (help) Traceback (most recent call last):  File "<stdin>", line 1, in <module> NameError: name 'sklearn' is not defined
any advice ? Much appreciated. Kind regards - e
Quote:ImportError: No module named scipy

Do you have 'scipy' and all it's requirements installed?
shouldn't it be:
import sklearn
No dot

.... Just noticed it has the dot in your text, but not where you actually did the import.
looks like missing module as sparkz_alot suggests
I so very much appreciate your reply and assistance.
Although in my forum post i did add the dot in the IDE I got it right. sorry for that.

I tried to download scipy and now i am down the rabbit hole and get the following:


when I type pip list

it returns:

certifi (2017.4.17)
chardet (3.0.4)
cycler (0.10.0)
functools32 (3.2.3.post2)
idna (2.5)
matplotlib (2.0.2)
nltk (3.2.4)
numpy (1.13.0)
oauthlib (2.0.2)
olefile (0.44)
pandas (0.20.2)
Pillow (4.1.1)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.0)
pytz (2017.2)
requests (2.18.1)
requests-oauthlib (0.8.0)
scikit-learn (0.18.1)
setuptools (20.10.1)
six (1.10.0)
sklearn (0.0)
textblob (0.12.0)
tweepy (3.5.0)
urllib3 (1.21.1)

When i type
C:\Python27\Scripts>pip install scipy

I get:

Collecting scipy
Using cached scipy-0.19.0.zip
Installing collected packages: scipy
Running setup.py install for scipy ... error
Complete output from command c:\python27\python.exe -u -c "import setuptools
, tokenize;__file__='c:\\users\\*****\\appdata\\local\\temp\\pip-build-ugqw2s\\
scipy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().repla
ce('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --reco
rd c:\users\*****\appdata\local\temp\pip-wokake-record\install-record.txt --sin
gle-version-externally-managed --compile:

Note: if you need reliable uninstall behavior, then install
with pip instead of using setup.py install:

- pip install . (from a git repo or downloaded source
release)
- pip install scipy (last SciPy release on PyPI)


lapack_opt_info:
lapack_mkl_info:
libraries mkl_rt not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
NOT AVAILABLE

openblas_lapack_info:
libraries openblas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python2
7\\libs']
NOT AVAILABLE

atlas_3_10_threads_info:
Setting PTATLAS=ATLAS
c:\python27\lib\site-packages\numpy\distutils\system_info.py:1051: UserWarni
ng: Specified path C:\projects\numpy-wheels-jc1cl\windows-wheel-builder\atlas-bu
ilds\atlas-3.10.1-sse2-32\lib is invalid.
pre_dirs = system_info.get_paths(self, section, key)
<class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
NOT AVAILABLE

atlas_3_10_info:
<class 'numpy.distutils.system_info.atlas_3_10_info'>
NOT AVAILABLE

atlas_threads_info:
Setting PTATLAS=ATLAS
<class 'numpy.distutils.system_info.atlas_threads_info'>
NOT AVAILABLE

atlas_info:
<class 'numpy.distutils.system_info.atlas_info'>
NOT AVAILABLE

c:\python27\lib\site-packages\numpy\distutils\system_info.py:572: UserWarnin
g:
Atlas (http://math-atlas.sourceforge.net/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [atlas]) or by setting
the ATLAS environment variable.
self.calc_info()
lapack_info:
libraries lapack not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
NOT AVAILABLE

c:\python27\lib\site-packages\numpy\distutils\system_info.py:572: UserWarnin
g:
Lapack (http://www.netlib.org/lapack/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [lapack]) or by setting
the LAPACK environment variable.
self.calc_info()
lapack_src_info:
NOT AVAILABLE

c:\python27\lib\site-packages\numpy\distutils\system_info.py:572: UserWarnin
g:
Lapack (http://www.netlib.org/lapack/) sources not found.
Directories to search for the sources can be specified in the
numpy/distutils/site.cfg file (section [lapack_src]) or by setting
the LAPACK_SRC environment variable.
self.calc_info()
NOT AVAILABLE

Running from scipy source directory.
non-existing path in 'scipy\\integrate': 'quadpack.h'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\ethang\appdata\local\temp\pip-build-ugqw2s\scipy\setup.py",
line 416, in <module>
setup_package()
File "c:\users\ethang\appdata\local\temp\pip-build-ugqw2s\scipy\setup.py",
line 412, in setup_package
setup(**metadata)
File "c:\python27\lib\site-packages\numpy\distutils\core.py", line 135, in
setup
config = configuration()
File "c:\users\ethang\appdata\local\temp\pip-build-ugqw2s\scipy\setup.py",
line 336, in configuration
config.add_subpackage('scipy')
File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 10
29, in add_subpackage
caller_level = 2)
File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 99
8, in get_subpackage
caller_level = caller_level + 1)
File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 93
5, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "scipy\setup.py", line 15, in configuration
config.add_subpackage('linalg')
File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 10
29, in add_subpackage
caller_level = 2)
File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 99
8, in get_subpackage
caller_level = caller_level + 1)
File "c:\python27\lib\site-packages\numpy\distutils\misc_util.py", line 93
5, in _get_configuration_from_setup_py
config = setup_module.configuration(*args)
File "scipy\linalg\setup.py", line 20, in configuration
raise NotFoundError('no lapack/blas resources found')
numpy.distutils.system_info.NotFoundError: no lapack/blas resources found

----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\
\users\\ethang\\appdata\\local\\temp\\pip-build-ugqw2s\\scipy\\setup.py';f=getat
tr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close
();exec(compile(code, __file__, 'exec'))" install --record c:\users\ethang\appda
ta\local\temp\pip-wokake-record\install-record.txt --single-version-externally-m
anaged --compile" failed with error code 1 in c:\users\ethang\appdata\local\temp
\pip-build-ugqw2s\scipy\
Scipy needs to be compiled, by default, Windows does not come with a compiler. The best way is to download the pre-compiled version from here: Windows Binaries make sure you download the correct wheel that matches your OS and Python. Note that when you look at Scipy, it tells you it requires Numpy. Again download this from the same site and install before you install Scipy.

From the command prompt, navigate to where you downloaded the files to and type pip install exact_file_name.whl

Do that first for numpy then scipy.
Since you are running windows, here is a possible solution:

Take a look at the Lightning pagkage: http://lightning-viz.org/
If this will do what you need, there is a 'gohike' wheel available for python 2.7, 3.4, 3.5, and 3.6
in both 32 bit and 64 bit versions here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lightning
these wheels have a reputation for being complete in that they will install all necessary dependencies

simply download the wheel to a convenient folder,
switch to that folder with a command window (preferably cmder see: http://cmder.net/)
and run
pip install wheelname
You could also use Anaconda.
Has pretty most all scientific packages pre-install package list.
It's a stand alone package,and will not use OS version of Python which you still can use.