Python installation scikit!!!

Source: Internet
Author: User

First of all, spit groove, really is tossing for a few days, a will update this, one will update that, always a variety of wonderful problems and so on:

Cannot import Check-build

Pip has a new version, need to be updated (yellow word)

The scipy error is the most, but it can be installed

The specified module could not be found

No model XXX

All sorts of updates just don't work.

But the bottom of the article is really a big help ... itself relatively lazy, do not want to uninstall after the update, so has been a variety of problems, read the following article, very useful, of course, some people may really just scipy incompatible, then you update on the good, if not yet, you have all deleted, new installation, pay attention to the installation sequence

Http://www.2cto.com/kf/201512/454271.html

There are also version issues,

。。。。。。。。。。。。。。。。。。。。。。。 The following is the article content

This article focuses on how Python installs NumPy, Scipy, Matlotlib, Scikit-learn, and other libraries, as well as the problem-solving methods that are encountered. Recently installed this is really a tear ah, a variety of incompatibility problems and error, I hope the article is helpful to you! Some of the problems you may encounter include:
Importerror:no module named Sklearn not installed Sklearn package
Importerror:dll load failed: The specified module could not be found
Importerror:dll load failed:the specified module could not being found

Microsoft Visual C + + 9.0 is required unable to find Vcvarsall.bat
Numpy Install runtimeerror:broken toolchain:cannot Link a simple C program
ImportError:numpy.core.multiarray failed to import
Importerror:cannot Import Name __check_build
Importerror:no module named Matplotlib.pyplot

I. Installation process

I was the first to use the "Pip install scikit-learn" command to install the Scikit-learn program, and did not notice the need to install Numpy, Scipy, Matlotlib, and then after the error "No module named Numpy", I then use pip or download EXE program to install the corresponding package, but also do not understand the importance of the installation sequence and version. Eventually the error "Importerror:dll load failed: The specified module could not be found", at this point my workaround is:

Error: Sklearn importerror:dll load failed: The specified module could not be found
Important: There are always compatibility issues when installing Python third-party libraries, which should be version issues, and the version needs to be consistent.

First Step: Uninstall the original version, including NumPy, Scipy, Matlotlib, Scikit-learn
pip Uninstall Scikit-learn
pip Uninstall NumPy
pip Uninstall scipy
pip Uninstall Matplotlib

The second step: Do not use "Pip Install package" or "easy_install" installation, or to Baidu \csdn download exe file, but to the official website to download the corresponding version.
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn

The most important part of the installation process is that the version needs to be compatible. Where the operating system is 64-bit, Python is 2.7.8 64-bit, download four WHL file as follows, where CP27 represents CPython 2.7 version, cp34 means CPython 3.4,win_arm64 refers to the 64-bit version.
Numpy-1.10.2-cp27-none-win_amd64.whl
Scipy-0.16.1-cp27-none-win_amd64.whl
Matplotlib-1.5.0-cp27-none-win_amd64.whl
Scikit_learn-0.17-cp27-none-win_amd64.whl

PS: It is not recommended to use "Pip install NumPy" to install or download similar files such as "Numpy-mkl-1.8.0.win-amd64-py2.7.exe", addresses such as:
Http://sourceforge.net/projects/numpy/files/NumPy
Http://sourceforge.net/projects/scipy/files/Scipy

PS (remember to download with MKL here)

Step three: go to python Install scripts directory , and then use PIP install XXX.WHL installation, first install Numpy\scipy\matlotlib package, then install Scikit-learn.

where my Python installation path is "G:\software\Program Software\python\python insert\scripts" while four WHL files install core code:
Pip Install G:\NUMPY+SCIPY+MATPLOTLIB\NUMPY-1.10.2-CP27-NONE-WIN_AMD64.WHL
Pip Install G:\NUMPY+SCIPY+MATPLOTLIB\SCIKIT_LEARN-0.17-CP27-NONE-WIN_AMD64.WHL


C:\>g:g:\>cd G:\software\Program Software\python\python insert\scriptsG:\software\Program Software\python\python Insert\scripts>pip Install g:\numpy+scipy+matplotlib\ Numpy-1.10.2-cp27-none-win_amd64.whlprocessing G:\numpy+scipy+matplotlib\numpy-1.10.2-cp27-none-win_ Amd64.whlinstalling collected packages:numpysuccessfully installed Numpy-1.10.2g:\software\program software\Python\ Python insert\scripts>pip Install g:\numpy+scipy+matplotlib\matplotlib-1.5.0-cp27-none-win_amd64.whlinstalling Collected packages:matplotlibsuccessfully installed Matplotlib-1.5.0g:\software\program Software\Python\python Insert\scripts>pip Install g:\numpy+scipy+matplotlib\scipy-0.16.1-cp27-none-win_amd64.whlprocessing g:\numpy+ Scipy+matplotlib\scipy-0.16.1-cp27-none-win_amd64.whlinstalling collected packages:scipysuccessfully installed Scipy-0.16.1g:\software\program Software\python\python Insert\scripts>pip Install g:\numpy+scipy+matplotlib\ Scikit_learn-0.17-cp27-none-win_amd64.whlprocessing G:\numpy+scipy+matplotlib\scikit_learn-0.17-cp27-none-win_ Amd64.whlinstaLling collected packages:scikit-learnsuccessfully installed scikit-learn-0.17 

Fourth step: The configuration is complete at this time, the key is Python64 bit version compatibility problem and scripts directory. Finally with Bupt forum a man of God's reply to end this installation process: "Silly child, with kit Ah, to introduce you to a anaconda or Winpython." Only to help you here! ”

。。。。。。。。。。。。。。。。。。。

Because of his time, you might not be able to find that version.

The following is my installation version for reference only:

。。。。。。。。。。。。。。。。。。。。

two. Test the operating environment


Why are you faking all this? Give several use cases to verify that it's properly installed and powerful!

Scikit-learn is a python-based machine learning module based on BSD open source licensing. The basic functions of scikit-learn are mainly divided into six parts, classification, regression, clustering, data dimensionality reduction, model selection, data preprocessing, and can refer to the documents on the official website.

The NumPy(Numeric python) system is an open-source numerical extension of Python, a scientific computing package implemented in Python. It provides a number of advanced numerical programming tools, such as matrix data types, vector processing, and sophisticated operations libraries. Designed for rigorous digital processing.
The content includes: 1, a powerful n-dimensional array object array;2, a relatively mature (broadcast) function library, 3, for the integration of C/D and Fortran Code Toolkit, 4, Practical linear algebra, Fourier transform and random number generation function. NumPy and sparse matrix Operations pack scipy are more convenient to use.

SciPy (pronounced "sigh Pie") is an open source mathematical, scientific, and engineering computing package. It is a convenient, easy-to-use, scientific and Engineered Python toolkit that includes statistics, optimization, integration, linear algebra modules, Fourier transforms, signal and image processing, ordinary differential equation solvers, and more.

matplotlib is a Python graphics framework, similar to the MATLAB and R languages. It is Python's most famous drawing library, which provides a complete set of command APIs similar to those of MATLAB, making it ideal for interactive mapping. It can also be easily used as a drawing control, embedded in GUI applications.


First code: Slash coordinates, test matplotlib

Import Matplotlibimport numpyimport scipyimport Matplotlib.pyplot as Pltplt.plot ([]) Plt.ylabel (' some numbers ') Plt.show ()

Operation Result:

The second code: Peach Heart Program, test NumPy and Matplotlib
Code reference: Installation of Python Easy_install under Windows-kingslanding

Import NumPy as Npimport matplotlib.pyplot as PltX = Np.arange ( -5.0, 5.0, 0.1) Y = Np.arange ( -5.0, 5.0, 0.1) x, y = np.meshg RID (x, y) F = * x * * 2-16 * NP.ABS (x) * y + + * y * * 2-225fig = plt.figure () cs = Plt.contour (x, Y, F, 0, colors = ' R ') Plt.show ()

Operation Result:



Third program: Show matplotlib powerful drawing interactive function
Code reference: Python-matplotlib installation and simple use-bery

Import NumPy as Npimport matplotlib.pyplot as plt n = 5menMeans = (   2, 3, 4, 1, 2) IND = N. P.arange (N)  # The X locations for the groupswidth = 0.35        # The width of the bars fig, ax = plt.subplots () Rects1 =  Ax.bar (Ind, Menmeans, Width, color= ' R ', yerr=menstd) Womenmeans = (   3, 5, 2, 3, 3) WOMENSTD = Ax.bar (Ind+width, Womenmeans, width, color= ' y ', yerr=womenstd) # Add Someax.set_ylabel (' Scores ') ax.set_title (' Scores By group and Gender ') ax.set_xticks (ind+width) ax.set_xticklabels ((' G1 ', ' G2 ', ' G3 ', ' G4 ', ' G5 ')) Ax.legend ((Rects1[0], R Ects2[0]), (' Men ', ' Women ')) def AutoLabel (rects):    # Attach some text labels for    rect in rects:        height = rect . Get_height ()        Ax.text (rect.get_x () +rect.get_width ()/2, 1.05*height, '%d '%int (height),                ha= ' center ', va= ' Bottom ') autolabel (rects1) AutoLabel (rects2) plt.show ()

Operation Result:



Fourth code: Matrix data set, test Sklearn

From Sklearn Import Datasetsiris = Datasets.load_iris () digits = Datasets.load_digits () print Digits.data

Operation Result:


Fifth code: Calculate TF-IDF Word weights, test scikit-learn data analysis (above and all test)
Reference code: http://blog.csdn.net/liuxuejiang158blog/article/details/31360765

# coding:utf-8__author__ = "Liuxuejiang" Import jiebaimport jieba.posseg as Psegimport osimport sysfrom sklearn Import feat Ure_extractionfrom sklearn.feature_extraction.text Import Tfidftransformerfrom Sklearn.feature_extraction.text  Import Countvectorizerif __name__ = = "__main__": corpus=["I came to Tsinghua University in Beijing", #第一类文本切词后的结果 words separated by a space "he came to NetEase hang research Building ", #第二类文本的切词结果" Xiao Ming Master's degree and Chinese Academy of Sciences ", #第三类文本的切词结果" I love Beijing Tian ' an gate "] #第四类文本的切词结果 #该类会将文本中的词语转    In terms of the word frequency matrix, matrix element A[i][j] means that J words under Class I text Vectorizer=countvectorizer () #该类会统计每个词语的tf-IDF weights Transformer=tfidftransformer () #第一个fit_transform是计算tf-IDF, the second fit_transform is to convert the text to a word frequency matrix Tfidf=transformer.fit_transform (Vectorizer.fit_transform ( CORPUS)) #获取词袋模型中的所有词语 word=vectorizer.get_feature_names () #将tf-IDF matrix extraction, Element A[i][j] represents the TF-IDF weight of J-Words in Class I text weight= Tfidf.toarray () #打印每类文本的tf-IDF word weights, the first for traversing all text, and the second for facilitating word weights under a certain type of text for I in range (len (weight)): Print U "----     ---here output the word tf-idf weight of the ", I,u" class text------"   For j in range (Len (word)): print Word[j],weight[i][j] 

Operation Result:

three. Other error resolution methods


Although there are several other errors and workarounds encountered during installation, the author recommends the above installation steps.

Before this, I repeatedly install, uninstall, upgrade package, which encountered a variety of errors, changed and changed, Baidu and Google. Common PIP usage is as follows:

* Pip Install numpy             --Install package numpy* pip Uninstall numpy           --Uninstall Package numpy* pip show--files packagename  --View installed package * Pip Lis T outdated             --View Pending update package information * PIP install--upgrade numpy   --Upgrade package * PIP Install-u packagename    --Upgrade Package * PIP Search Packages Name        --Search for Package * pip                      help--Show helpful information


ImportError:numpy.core.multiarray failed to import
Python Install NumPy error, this through StackOverflow and Baidu also need Python version and numpy version of the same, the solution includes "Pip Install-u numpy" upgrade or download the specified version "Pip install numpy==1.8 ". But this obviously also involves more packages, without the previous uninstall download installed in the unified version of WHL.

Microsoft Visual C + + 9.0 is required (unable to find Vcvarsall.bat)
Because the NumPy internal matrix operation is implemented in C, it is necessary to install the compiler tool, which is related to VC + + or VS2012 installed on the computer, workaround: If you have installed Visual Studio, add the environment variable Vs90comntools. Different vs versions correspond to different environment variable values:
Visual Studio (VS10) Settings vs90comntools=%vs100comntools%
Visual Studio (VS11) Settings vs90comntools=%vs110comntools%
Visual Studio (VS12) Settings vs90comntools=%vs120comntools%
But this is not resolved, and the other option is to download the Micorsoft Visual C + + Compiler for Python 2.7 package.

PS: The basic solution to these problems is to use PIP upgrade, version consistent, re-download the relevant version of EXE file and then install.

Hope to help you

Of course, some foreign-language posts that let you in the cannot import check-build time to delete the Sklearn in the import check-build that a few words, of course, will not give an error, but you have to delete else that paragraph, or the next sentence is wrong again, and deleted just guarantee you import Sklearn time Yes, once you want to use the algorithm in Sklearn, or will be wrong, can not solve the problem,,,, do not worry about trouble, re-install it

Python installation scikit!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.