GloVe for Python 3.7 版本

Posted

技术标签:

【中文标题】GloVe for Python 3.7 版本【英文标题】:GloVe for Python 3.7 version 【发布时间】:2020-05-31 20:43:13 【问题描述】:

我正在尝试在 Python 3.7 版上从 Pypi 安装 GloVe 包,但它一直返回下面写的相同错误。有什么方法可以使用手套吗?我也尝试从https://github.com/stanfordnlp/GloVe 安装它,但它也以错误结束。 谢谢您的帮助!

pip install glove Collecting glove   Using cached glove-1.0.2.tar.gz (44 kB) Requirement already satisfied: numpy in d:\anaconda\lib\site-packages (from glove) (1.16.4) Building wheels for collected packages: glove   Building wheel for glove (setup.py) ... error   ERROR: Command errored out with exit status 1:    command: 'd:\anaconda\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-vlqonr2u\\glove\\setup.py'"'"';
__file__='"'"'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-vlqonr2u\\glove\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\Dell\AppData\Local\Temp\pip-wheel-c3ip0qox'
       cwd: C:\Users\Dell\AppData\Local\Temp\pip-install-vlqonr2u\glove\   Complete output (67 lines):   running bdist_wheel   running build   running build_py   creating build   creating build\lib.win-amd64-3.7   creating build\lib.win-amd64-3.7\glove   copying glove\glove.py -> build\lib.win-amd64-3.7\glove   copying glove\__init__.py -> build\lib.win-amd64-3.7\glove   running egg_info   writing glove.egg-info\PKG-INFO   writing dependency_links to glove.egg-info\dependency_links.txt   writing requirements to glove.egg-info\requires.txt   writing top-level names to glove.egg-info\top_level.txt   reading manifest file 'glove.egg-info\SOURCES.txt'   Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\Dell\AppData\Local\Temp\pip-install-vlqonr2u\glove\setup.py", line 85, in <module>
      include_package_data=True,
    File "d:\anaconda\lib\site-packages\setuptools\__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "d:\anaconda\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "d:\anaconda\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "d:\anaconda\lib\site-packages\wheel\bdist_wheel.py", line 223, in run
      self.run_command('build')
    File "d:\anaconda\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "d:\anaconda\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "d:\anaconda\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 53, in run
      self.build_package_data()
    File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 118, in build_package_data
      for package, src_dir, build_dir, filenames in self.data_files:
    File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 66, in __getattr__
      self.data_files = self._get_data_files()
    File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 82, in _get_data_files
      self.analyze_manifest()
    File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 138, in analyze_manifest
      self.run_command('egg_info')
    File "d:\anaconda\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 297, in run
      self.find_sources()
    File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 304, in find_sources
      mm.run()
    File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 535, in run
      self.add_defaults()
    File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 579, in add_defaults
      self.read_manifest()
    File "d:\anaconda\lib\site-packages\setuptools\command\sdist.py", line 220, in read_manifest
      self.filelist.append(line)
    File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 477, in append
      path = convert_path(item)
    File "d:\anaconda\lib\distutils\util.py", line 110, in convert_path
      raise ValueError("path '%s' cannot be absolute" % pathname)   ValueError: path '/Users/jonathanraiman/Desktop/Coding/python_packages/glove/glove/glove_inner.cpp' cannot be absolute   ----------------------------------------   ERROR: Failed building wheel for glove   Running setup.py clean for glove Failed to build glove Installing collected packages: glove
    Running setup.py install for glove ... error
    ERROR: Command errored out with exit status 1:
     command: 'd:\anaconda\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-vlqonr2u\\glove\\setup.py'"'"';
__file__='"'"'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-vlqonr2u\\glove\\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\Dell\AppData\Local\Temp\pip-record-mo9f0x8b\install-record.txt'
--single-version-externally-managed --compile --install-headers 'd:\anaconda\Include\glove'
         cwd: C:\Users\Dell\AppData\Local\Temp\pip-install-vlqonr2u\glove\
    Complete output (69 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\glove
    copying glove\glove.py -> build\lib.win-amd64-3.7\glove
    copying glove\__init__.py -> build\lib.win-amd64-3.7\glove
    running egg_info
    writing glove.egg-info\PKG-INFO
    writing dependency_links to glove.egg-info\dependency_links.txt
    writing requirements to glove.egg-info\requires.txt
    writing top-level names to glove.egg-info\top_level.txt
    reading manifest file 'glove.egg-info\SOURCES.txt'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Dell\AppData\Local\Temp\pip-install-vlqonr2u\glove\setup.py", line 85, in <module>
        include_package_data=True,
      File "d:\anaconda\lib\site-packages\setuptools\__init__.py", line 144, in setup
        return distutils.core.setup(**attrs)
      File "d:\anaconda\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "d:\anaconda\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "d:\anaconda\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "d:\anaconda\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "d:\anaconda\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "d:\anaconda\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "d:\anaconda\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 53, in run
        self.build_package_data()
      File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 118, in build_package_data
        for package, src_dir, build_dir, filenames in self.data_files:
      File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 66, in __getattr__
        self.data_files = self._get_data_files()
      File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 82, in _get_data_files
        self.analyze_manifest()
      File "d:\anaconda\lib\site-packages\setuptools\command\build_py.py", line 138, in analyze_manifest
        self.run_command('egg_info')
      File "d:\anaconda\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "d:\anaconda\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 297, in run
        self.find_sources()
      File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 304, in find_sources
        mm.run()
      File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 535, in run
        self.add_defaults()
      File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 579, in add_defaults
        self.read_manifest()
      File "d:\anaconda\lib\site-packages\setuptools\command\sdist.py", line 220, in read_manifest
        self.filelist.append(line)
      File "d:\anaconda\lib\site-packages\setuptools\command\egg_info.py", line 477, in append
        path = convert_path(item)
      File "d:\anaconda\lib\distutils\util.py", line 110, in convert_path
        raise ValueError("path '%s' cannot be absolute" % pathname)
    ValueError: path '/Users/jonathanraiman/Desktop/Coding/python_packages/glove/glove/glove_inner.cpp' cannot be absolute
    ---------------------------------------- ERROR: Command errored out with exit status 1: 'd:\anaconda\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-vlqonr2u\\glove\\setup.py'"'"';
__file__='"'"'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-vlqonr2u\\glove\\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\Dell\AppData\Local\Temp\pip-record-mo9f0x8b\install-record.txt'
--single-version-externally-managed --compile --install-headers 'd:\anaconda\Include\glove' Check the logs for full command output.<

【问题讨论】:

您是否尝试在 Windows 中构建它?也许你必须使用linux系统。请为输出日志添加换行符以使其可读 是的,我使用 Windows。我不确定这是否是您要求的,但在我的 LOG_FILE 中,我发现:2020-02-17T01:42:40,430 File "d:\anaconda\lib\distutils\util.py", line 110, in convert_path 2020-02-17T01:42:40,430 raise ValueError("path '%s' cannot be absolute" % pathname) 2020-02-17T01:42:40,430 ValueError: path '/Users/jonathanraiman/Desktop/Coding/python_packages/glove/glove/glove_inner.cpp' cannot be absolute 2020-02-17T01:42:40,498 ERROR: Failed building wheel for glove 2020-02-17T01:42:40,500 Running setup.py clean for glove 你试过 conda 吗? 您的意思是“conda install glove”吗?我试过了,但是 glove 是一个库中的包,到目前为止我还没有找到另一种使用 conda 安装包的方法 @Black 你需要@我才能允许 *** 向我发送通知 【参考方案1】:

您可以源安装它。然后从github克隆它

pip install .

【讨论】:

我一直在尝试这样做,但它返回 ERROR: Directory '.' is not installable. Neither 'setup.py' nor 'pyproject.toml' found. 我还在 git 上安装了 python,但这也不起作用 @Black 您问题中的链接不是 Pypi 包源文件。检查这个github.com/JonathanRaiman/glove 我已经克隆了那个 repo ([link] github.com/JonathanRaiman/glove) 然后pip install . 但是现在我有这个错误ImportError: Building module glove.glove_inner failed: ['distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat\n']。根据bugs.python.org/issue35699,这是一个已解决的错误.. @Black 您使用的是什么版本的 python 3.7。你能升级到 3.7.3+ 我在 3.7.3 上工作。我试图降级它,但什么也没发生。【参考方案2】:

如果您可以对原始 GloVe 实现稍作修改,您可以使用“手套”。它使用与 GloVe 相同的算法,但对目标函数进行了矢量化,并且还使用了“热启动”(手套比手套更暖和)。

来自文档:mittens 从通用的预训练表示开始,并将它们调整到一个专门的领域。pip install -U mittens 那么:from mittens import GloVe

https://github.com/roamanalytics/mittens#mittens

【讨论】:

只是想补充一点,认为from mittens import GloVe 给出了斯坦福软件包中描述的精确算法。如果你想要“热启动”的东西,那就是另一个类:from mittens import Mittens

以上是关于GloVe for Python 3.7 版本的主要内容,如果未能解决你的问题,请参考以下文章

Python环境问题及解决方案

GloVe: Global Vectors for Word Representation阅读总结

GloVe: Global Vectors for Word Representation阅读总结

python client.py

升级为python3.3.7版本步骤

python版本升级到3.7