申請了博客以后都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 >>>
安裝成功!