Python 找不到库 geos_c 或加载其任何变体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19742406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:29:15  来源:igfitidea点击:

Could not find library geos_c or load any of its variants

pythonshapely

提问by user2947767

I use python in fedora 19. I wanted to run the following line Python: import shapely.geometrythe following error appears:

我在 fedora 19 中使用 python。我想运行以下行 Python: import shapely.geometry出现以下错误:

OSError: Could not find or load any library geos_c icts of variants ['libgeos_c.so.1', 'libgeos_c.so']

OSError: 无法找到或加载变体 ['libgeos_c.so.1', 'libgeos_c.so'] 的任何库 geos_c icts

I installed the package Shapely, and the following two libraries:

我安装了 Shapely 包,以及以下两个库:

glibc-2.17-4.fc19.i686.rpm

glibc-2.17-4.fc19.i686.rpm

geos-3.3.8-2.fc19.i686.rpm

geos-3.3.8-2.fc19.i686.rpm

I just looked for the solution of this problem on the web, but I have not found

刚刚在网上找了下这个问题的解决方法,没找到

Please, help me !

请帮我 !

回答by Seth

Shapely loads geos via ctypes.

通过 ctypes整齐地加载 geos

Try this in your python and see if you get anything:

在你的 python 中试试这个,看看你是否得到了什么:

from ctypes.util import find_library
find_library('geos_c')

If it doesn't work, then your geos installation is probably messed up. According to this, your geos should be in /usr/lib/libgeos_c.so.1. Is your library actually there?

如果它不起作用,那么您的 geos 安装可能搞砸了。根据这个,你GEOS应该是/usr/lib/libgeos_c.so.1。你的图书馆真的在那里吗?

回答by PaF

Installed shapely using pip, and had the same problem. So I went ahead and installed it like so:

使用 pip 安装整齐,并有同样的问题。所以我继续安装它,如下所示:

sudo apt-get install libgeos-dev

And it worked. I'm running Ubuntu, so if you're on Fedora, you should run:

它奏效了。我正在运行 Ubuntu,所以如果你在 Fedora 上,你应该运行:

sudo yum install geos-devel

回答by test44

set the LD_LIBRARY_PATH, then run python

设置LD_LIBRARY_PATH,然后运行python

export LD_LIBRARY_PATH=/path_to/geos/lib:$LD_LIBRARY_PATH

python mytest.py

回答by Nick

If you're using Anaconda like I am and ran into this, copy the libgeos* files from /usr/lib to the anaconda/lib directory and try again... :) Hopefully this saves someone else, cause I have spent hours on this.

如果您像我一样使用 Anaconda 并且遇到了这个问题,请将 libgeos* 文件从 /usr/lib 复制到 anaconda/lib 目录并重试... :) 希望这可以拯救其他人,因为我已经花了几个小时这个。

回答by Devdatta Tengshe

I had the same problem, and to solve it, you need to add the lib path to ld.so.conf file.

我遇到了同样的问题,要解决它,您需要将 lib 路径添加到 ld.so.conf 文件中。

To do this, Open the file:

为此,请打开文件:

sudo vi /etc/ld.so.conf

add this line

添加这一行

/usr/local/lib

And then

进而

sudo /sbin/ldconfig

回答by Bob Baxley

On Fedora install geos and geos-devel

在 Fedora 上安装 geos 和 geos-devel

sudo yum install geos geos-devel

回答by Paco Bahena

In ubuntu, the following commands should take care of it. It all goes down to the following packages.

在 ubuntu 中,以下命令应该处理它。这一切都归结为以下软件包。

(Original 2017)

(2017 年原创)

sudo apt-get install libgeos-c1 libgeos-3.4.2

EDIT:(updated versions 2020)

编辑:(更新版本 2020)

sudo apt-get install libgeos-c1v5 libgeos-3.7.1

回答by Sat

I had no problem on Jupyter Notebook but when I used PyCharm I encountered this issue. Tried multiple things windows on machine and the below troubleshooting steps fixed the issue

我在 Jupyter Notebook 上没有问题,但是当我使用 PyCharm 时我遇到了这个问题。在机器上尝试了多个窗口,以下故障排除步骤解决了该问题

pip install geos

Go to PyCharm, File->Settings->Project->Project Interpreter(Check you have the right path where your python.exe file is there)->Add enter image description here

转到 PyCharm,文件->设置->项目->项目解释器(检查您的 python.exe 文件所在的路径是否正确)->添加 在此处输入图片说明

Check that, on Virtualenv Environment -> Base Interpreter pointing to the right location where you have the python.exe

检查一下,在 Virtualenv Environment -> Base Interpreter 指向正确的位置,你有 python.exe

Same for System Interpreter->Interpreter And also Pipenv Environment -> Base Interpreter

System Interpreter->Interpreter 以及 Pipenv Environment -> Base Interpreter 相同

enter image description here

在此处输入图片说明

Make sure all are pointing to the right path. I encountered this problem as I have multiple IDE and hence multiple directories where python.exe is available.They were pointing to incorrect directories.

确保所有人都指向正确的路径。我遇到了这个问题,因为我有多个 IDE,因此有多个目录,其中 python.exe 可用。他们指向不正确的目录。

During the troubleshooting I also uninstalled and re installed conda install shapelyas I am pointing to Anaconda directory from PyCharm. Hope it helps.

在故障排除期间,我还卸载并重新安装, conda install shapely因为我从 PyCharm 指向 Anaconda 目录。希望能帮助到你。

Below link is also helpful https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#conda-package-manager

下面的链接也很有帮助https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#conda-package-manager