安裝了一天的gensim,其中因為版本不一致等等各種問題糾結了好久,現記錄如下:
正確安裝方式:
1. 安裝python2.7
2. 下載Python Extension Packages對應版本的numpy、scipy、gensim
3. 進入python安裝目錄下的Scripts目錄
執行: pip install numpy***.whl
pip install scipy***.whl
pip install gensim.whl
測試:輸入python命令進入python命令行,分別輸入 import numpy; import scipy; import gensim;沒有報錯,即安裝成功!
很簡單啊~可是我就是倒騰了一天,原因大體歸結為 版本不一致。
1. 原本機子上是有numpy和scipy的,但是以前貌似安裝的win32版本的擴展包,存在沖突,所以gensim安裝不了。
2. 卸載了原先裝的numpy和scipy,參照 官網Gensim Installation,使用pip或者easy_install安裝numpy\scipy,numpy成功,scipy報錯“LAPACK and BLAS libraries not found”,
解釋1、解釋2、解釋3等等都提到說需要Microsoft Visual C++ Compiler for Python 2.7,可是還是報這個錯。
3. 安裝時還遇到問題 —安裝第三方庫出現 Python version 2.7 required, which was not found in the registry,
運行腳本
import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!" if __name__ == "__main__": RegisterPy()
3. 后來我試了pip install scipy**.whl 方法,安裝scipy成功但是gensim不行,Github 解壓,使用命令:python setup.py install ,安裝有錯。
4. 使用pip裝whl文件,導入測試時有錯誤。
顯示scipy包有問題。
5. 卸載了numpy、scipy,使用前面說的方法重新來過,就可以了。。
這個故事告訴我們,凡事都要從一而終,都是用pip install ***.whl才行。