安装Gensim

安装了一天的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安装numpyscipy,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才行。

原文地址:https://www.cnblogs.com/yiruparadise/p/5502852.html