申请了博客以后都1年多了,一个博客也没发,今天突然起了这个念头,记录一下今天上午处理的一个问题。
一个朋友想使用word2vec来进行一些分词方面的工作,但是安装了之后爆出很多错误,拜托我帮个忙。研究了一个多小时,大致搞清楚了前因后果,把这个过程记录下来。至于为什么不是gensim来做分词,那又是另外一件事情,前因后果这里就不说了。
系统环境: windows7,python3.6
问题一: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 24: invalid continuation byte




if sys.version_info >= (3,): def console_to_str(s): try: return s.decode(sys.__stdout__.encoding) except UnicodeDecodeError: try: return s.decode('utf_8') except UnicodeDecodeError: return s.decode('gbk')
再执行命令pip install word2vec, 编码问题没有了,可是又出现新的问题。
问题2:系统找不到指定文件
Complete output from command C:\ProgramData\Anaconda2\envs\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-build-jpsvn2ro\\w
c\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ADMINI~1\AppData\Loca
\pip-a2480mto-record\install-record.txt --single-version-externally-managed --compile:
running install
Compilation command: gcc C:\Users\ADMINI~1\AppData\Local\Temp\pip-build-jpsvn2ro\word2vec\word2vec\c\win32/word2vec.c -o Scripts\word2vec.exe -O2 -Wall -funroll-loops
error: [WinError 2] 系统找不到指定的文件。
问题3: fatal error: win32-port.h: No such file or directory
Complete output from command C:\ProgramData\Anaconda2\envs\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-build-21ut_hht\\word
c\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ADMINI~1\AppData\Local\T
\pip-m1frjwvp-record\install-record.txt --single-version-externally-managed --compile:
running install
Compilation command: gcc C:\Users\ADMINI~1\AppData\Local\Temp\pip-build-21ut_hht\word2vec\word2vec\c\win32/word2vec.c -o Scripts\word2vec.exe -O2 -Wall -funroll-loops
C:\Users\ADMINI~1\AppData\Local\Temp\pip-build-21ut_hht\word2vec\word2vec\c\win32/word2vec.c:21:25: fatal error: win32-port.h: No such file or directory
# include "win32-port.h"
^
compilation terminated.
----------------------------------------
mand "C:\ProgramData\Anaconda2\envs\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-build-21ut_hht\\word2vec\\setup.py';f=getatt
okenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ADMINI~1\AppData\Local\Temp\pip-m1frjwvp-record\
tall-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\ADMINI~1\AppData\Local\Temp\pip-build-21ut_hht\word2vec\
上面错误信息的大意是,在编译的过程中发现include "win32-port.h"这个导入操作没有成功,没有这个文件。
到pypi网站的word2vec模块的下载页面下去看,发现一个github地址https://pypi.python.org/pypi/word2vec,上面有这个模块的源码。进去之后看说明发现windows安装该模块还需要win32-port,原话是:Windows: Very experimental support based this win32 port,
点击进入win32_port的开源项目,下载win32-port的zip包。
处理过程:
1. 下载一个word2vec的程序包,可以在pypi上下载,也可以在github上下载。因为需要改变安装包中的内容,我们需要换一种安装方式;
2. 下载一个win32-port zip包。
3. 将win32-port中的所有内容拷贝到word2vec模块的word2vec-0.9.2\word2vec\c\win32这个目录下;
4. 再到word2vec模块的文件夹下使用python setup.py install 来安装。
接下来就没有新问题了。
到python3的idle里,
>>> import word2vec >>> print(word2vec.__version__) 0.9.2 >>>
安装成功!