在windows上用conda安装pyhanlp

2022-04-28  本文已影响0人  竹霖聴雨

一、安装pyhanlp

安装pyhanlp需提前配置好jdk环境,我用的jdk版本是javac 1.8.0_60。然后执行下面命令行安装pyhanlp。

conda install -c conda-forge jpype1
pip install pyhanlp

二、解决安装时的报错AttributeError: 'Distribution' object has no attribute 'convert_2to3_doctests'

解决方案:检查当前setuptools版本是59.6.0,将其降低为58.5.3。顺便在下面贴出详细报错,有相同问题小伙伴可参考:

Collecting pyhanlp
  Using cached pyhanlp-0.1.84.tar.gz (136 kB)
Requirement already satisfied: jpype1==0.7.0 in d:\anaconda3\envs\py36\lib\site-packages (from pyhanlp) (0.7.0)
Requirement already satisfied: hanlp-downloader in d:\anaconda3\envs\py36\lib\site-packages (from pyhanlp) (0.0.25)
Requirement already satisfied: requests in d:\anaconda3\envs\py36\lib\site-packages (from hanlp-downloader->pyhanlp) (2.27.1)
Requirement already satisfied: charset-normalizer~=2.0.0 in d:\anaconda3\envs\py36\lib\site-packages (from requests->hanlp-downloader->pyhanlp) (2.0.12)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\anaconda3\envs\py36\lib\site-packages (from requests->hanlp-downloader->pyhanlp) (1.26.9)
Requirement already satisfied: certifi>=2017.4.17 in d:\anaconda3\envs\py36\lib\site-packages (from requests->hanlp-downloader->pyhanlp) (2020.6.20)
Requirement already satisfied: idna<4,>=2.5 in d:\anaconda3\envs\py36\lib\site-packages (from requests->hanlp-downloader->pyhanlp) (3.3)
Building wheels for collected packages: pyhanlp
  Building wheel for pyhanlp (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'D:\anaconda3\envs\py36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-eadekm80\\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\\setup.py'"'"'; __file__='"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-eadekm80\\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-wheel-ky3kl5q9'
       cwd: C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-eadekm80\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\
  Complete output (51 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib
  creating build\lib\pyhanlp
  copying pyhanlp\main.py -> build\lib\pyhanlp
  copying pyhanlp\server.py -> build\lib\pyhanlp
  copying pyhanlp\util.py -> build\lib\pyhanlp
  copying pyhanlp\__init__.py -> build\lib\pyhanlp
  creating build\lib\pyhanlp\static
  copying pyhanlp\static\__init__.py -> build\lib\pyhanlp\static
  running egg_info
  writing pyhanlp.egg-info\PKG-INFO
  writing dependency_links to pyhanlp.egg-info\dependency_links.txt
  writing entry points to pyhanlp.egg-info\entry_points.txt
  writing requirements to pyhanlp.egg-info\requires.txt
  writing top-level names to pyhanlp.egg-info\top_level.txt
  reading manifest file 'pyhanlp.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'pyhanlp.egg-info\SOURCES.txt'
  copying pyhanlp\static\hanlp.properties.in -> build\lib\pyhanlp\static
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-eadekm80\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\setup.py", line 57, in <module>
      'hanlp=pyhanlp.main:main',
    File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\__init__.py", line 163, in setup
      return distutils.core.setup(**attrs)
    File "D:\anaconda3\envs\py36\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "D:\anaconda3\envs\py36\lib\site-packages\wheel\bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "D:\anaconda3\envs\py36\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "D:\anaconda3\envs\py36\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "D:\anaconda3\envs\py36\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 974, in run_command
      cmd_obj.run()
    File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\command\build_py.py", line 58, in run
      self.build_package_data()
    File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\command\build_py.py", line 132, in build_package_data
      srcfile in self.distribution.convert_2to3_doctests):
  AttributeError: 'Distribution' object has no attribute 'convert_2to3_doctests'
  ----------------------------------------
  ERROR: Failed building wheel for pyhanlp
  Running setup.py clean for pyhanlp
Failed to build pyhanlp
Installing collected packages: pyhanlp
    Running setup.py install for pyhanlp ... error
    ERROR: Command errored out with exit status 1:
     command: 'D:\anaconda3\envs\py36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-eadekm80\\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\\setup.py'"'"'; __file__='"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-eadekm80\\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-8e88col2\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\anaconda3\envs\py36\Include\pyhanlp'
         cwd: C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-eadekm80\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\
    Complete output (53 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib
    creating build\lib\pyhanlp
    copying pyhanlp\main.py -> build\lib\pyhanlp
    copying pyhanlp\server.py -> build\lib\pyhanlp
    copying pyhanlp\util.py -> build\lib\pyhanlp
    copying pyhanlp\__init__.py -> build\lib\pyhanlp
    creating build\lib\pyhanlp\static
    copying pyhanlp\static\__init__.py -> build\lib\pyhanlp\static
    running egg_info
    writing pyhanlp.egg-info\PKG-INFO
    writing dependency_links to pyhanlp.egg-info\dependency_links.txt
    writing entry points to pyhanlp.egg-info\entry_points.txt
    writing requirements to pyhanlp.egg-info\requires.txt
    writing top-level names to pyhanlp.egg-info\top_level.txt
    reading manifest file 'pyhanlp.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'pyhanlp.egg-info\SOURCES.txt'
    copying pyhanlp\static\hanlp.properties.in -> build\lib\pyhanlp\static
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-eadekm80\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\setup.py", line 57, in <module>
        'hanlp=pyhanlp.main:main',
      File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\__init__.py", line 163, in setup
        return distutils.core.setup(**attrs)
      File "D:\anaconda3\envs\py36\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "D:\anaconda3\envs\py36\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "D:\anaconda3\envs\py36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "D:\anaconda3\envs\py36\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "D:\anaconda3\envs\py36\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "D:\anaconda3\envs\py36\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\command\build_py.py", line 58, in run
        self.build_package_data()
      File "D:\anaconda3\envs\py36\lib\site-packages\setuptools\command\build_py.py", line 132, in build_package_data
        srcfile in self.distribution.convert_2to3_doctests):
    AttributeError: 'Distribution' object has no attribute 'convert_2to3_doctests'
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'D:\anaconda3\envs\py36\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-eadekm80\\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\\setup.py'"'"'; __file__='"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-eadekm80\\pyhanlp_cea05a88f02f4b76af22b051cc3ece7c\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-8e88col2\install-record.txt' --single-version-externally-managed --compile --install-headers 'D:\anaconda3\envs\py36\Include\pyhanlp' Check the logs for full command output.
上一篇下一篇

猜你喜欢

热点阅读