python word2vec 无法安装
我一直在尝试在我的Windows 7电脑上安装word2vec,使用的是Python 2.7的解释器:https://github.com/danielfrg/word2vec
我试过下载压缩包,然后在解压后的目录里运行python setup.py
install,也试过用pip install
来安装,但无论哪种方式都出现了下面的错误:
Downloading/unpacking word2vec
Downloading word2vec-0.5.1.tar.gz
Running setup.py egg_info for package word2vec
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\georgioa\appdata\local\temp\pip_build_georgioa\word2vec\setup.py", line 17, in <module>
subprocess.call(['make', '-C', 'word2vec-c'])
File "C:\Python27\lib\subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\georgioa\appdata\local\temp\pip_build_georgioa\word2vec\setup.py", line 17, in <module>
subprocess.call(['make', '-C', 'word2vec-c'])
File "C:\Python27\lib\subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
似乎在访问subprocess.call()
时出现了问题,所以我在网上查了一下,成功地在word2vec的setup.py
文件中加上了shell=True
,结果又出现了这个错误:
'make' is not recognized as an internal or external command,
operable program or batch file.
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
running install
running build
running build_py
running install_lib
running install_data
error: can't copy 'bin\word2vec': doesn't exist or not a regular file
说实话,我现在也不知道该怎么继续了。我还尝试安装了make,并把路径变量设置为安装中的.exe文件,任何建议都非常感谢,谢谢。
更新:
虽然word2vec模块无法正常工作,但有一个叫gensim
的包似乎运行得很好,它还有一些很棒的自然语言处理功能,链接在这里:http://radimrehurek.com/gensim/
6 个回答
我成功在Windows上使用Cygwin编译并运行了原版的word2vec代码(https://github.com/dav/word2vec)。不过,我更喜欢使用gensim这个包,因为它对UTF-8编码没有问题,而原来的代码在处理非ASCII字符时会出错。
看起来这个软件包里包含了C语言的代码,并且使用了UN*X的makefile,所以它并不是为Windows系统写的。你可以试着找找有没有已经编译好的Windows版本。
使用 pip
来安装 Python 库是个不错的方法。
1. 安装 pip
A) 以管理员身份打开命令提示符
点击开始,选择所有程序,然后点击附件。
右键点击命令提示符,然后选择“以管理员身份运行”。
如果出现用户账户控制对话框,确认显示的操作是你想要的,然后点击继续。
B) 下载 get-pip.py,注意要保存为 .py 文件,而不是 .txt 文件。然后在命令提示符中运行它。
输入命令:python get-pip.py
下载 get-pip.py
,并保存为 get-pip.py
(不是 get-pip.txt
)。
在命令提示符中运行它。
python get-pip.py
2. 安装 word2vec
现在你可以用下面的命令来安装它:
pip install word2vec
对我来说,这种方法在Windows 7和Windows 8上都能用。
- 首先,安装64位的Anaconda(选择Python 2.7版本)。
- 接着,安装MinGW基本编译器(在安装列表中确保选择了C和C++编译器)。
- 然后,在Anaconda中重新安装gensim,使用命令“conda install gensim”。这样你就可以打开ipython-notebook,尝试运行使用word2vec的Python代码,应该能正常工作。
word2vec是为Linux系统设计的。你可以查看这个链接了解更多信息:https://github.com/danielfrg/word2vec
在页面底部提到,有一个非常实验性的Windows版本,可以在这里找到:https://github.com/zhangyafeikimi/word2vec-win32
编辑:
看起来你也可以安装gensim库,链接在这里:https://pypi.python.org/pypi/gensim
然后执行:
from gensim.models import word2vec