Python中的地理库问题

时间:2017-04-21 07:01:43

标签: python python-3.x nltk

我想使用地理库来提取地点的细节。我无法安装它。我安装了枕头,报纸,lxml,beautifulsoup4和所有nltk Corpas。在安装报纸的时候,它在distribute-0.6.21库中给了我一个错误,所以我安装了它,之后,我正面临着我试图安装的每个模块的错误:

$ conda install newspaper

Traceback (most recent call last):
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/exceptions.py", line 626, in conda_exception_handler
    return_value = func(*args, **kwargs)
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/cli/main.py", line 85, in _main
    from ..base.context import context
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/base/context.py", line 18, in <module>
    from .._vendor.auxlib.path import expand
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/_vendor/auxlib/path.py", line 8, in <module>
    import pkg_resources
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/pkg_resources.py", line 45
    def _bypass_ensure_directory(name, mode=0777):
                                               ^
SyntaxError: invalid token

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/palakagrawal/anaconda/bin/conda", line 6, in <module>
    sys.exit(conda.cli.main())
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/cli/main.py", line 162, in main
    return conda_exception_handler(_main, *args)
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/exceptions.py", line 630, in conda_exception_handler
    return handle_exception(e)
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/exceptions.py", line 620, in handle_exception
    print_unexpected_error_message(e)
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/exceptions.py", line 561, in print_unexpected_error_message
    from conda.base.context import context
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/base/context.py", line 18, in <module>
    from .._vendor.auxlib.path import expand
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/conda/_vendor/auxlib/path.py", line 8, in <module>
    import pkg_resources
  File "/Users/palakagrawal/anaconda/lib/python3.5/site-packages/pkg_resources.py", line 45
    def _bypass_ensure_directory(name, mode=0777):
                                               ^
SyntaxError: invalid token

请帮助我解决上述错误并建议我安装地理模块的方法

4 个答案:

答案 0 :(得分:2)

如果你使用的是Python 3,你应该确保你使用的所有软件包都与Python 3兼容。你得到的错误是由Python3中新的八进制数语法引起的,所以下面一行:

DATA                   D2
---------------------- ----------------------------------------
1234554554.87893       1234554554.8789344000

应该是:

def _bypass_ensure_directory(name, mode=0777):

for Python 3.您收到此错误,因为该程序包不是为Python 3设计的。

答案 1 :(得分:1)

接受答案的一些补充:

事实上,Kamyar建议的geograpy only supports Python 2,很明显。

除非地名提取是您的 Python任务,否则我建议您找到一种方法来完成与Python一起使用的方法3.选择其他地理包,或者如果您的目标是实体识别直接使用nltk,它支持Python 3(geograpy在后​​台使用nltk)。自{2014}以来,套餐geograpy尚未更新,因此您可以找到更符合您需求的其他内容。

如果你决定在Python2下运行它,请使用conda create --name new_env_name python=2为它创建一个新的Anaconda环境。有关详细信息,请参阅https://conda.io/docs/py2or3.html#install-a-different-version-of-python。然后,您可以使用Anaconda命令activate(例如. activate new_env_name)在您的环境之间切换。

答案 2 :(得分:1)

如果您使用的是python3,请使用: pip3安装geograpy3

答案 3 :(得分:0)

有一个python 3版本/ fork,geogra py3 有关安装说明,请检查https://pypi.org/project/geograpy3/