简体   繁体   English

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

[英]Could not find library geos_c or load any of its variants

I use Python in Fedora 19. I wanted to run the following line:我在 Fedora 19 中使用 Python。我想运行以下行:

import shapely.geometry

but the following error appears:但出现以下错误:

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

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。

What can I do to solve the problem?我能做些什么来解决这个问题?

Installed shapely using pip, and had the same problem.使用 pip 安装得体,并且遇到了同样的问题。 So I went ahead and installed it like so:所以我继续安装它,如下所示:

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

On MACOS you can run:在 MACOS 上,您可以运行:

brew install geos

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

In ubuntu, the following commands should take care of it.在 ubuntu 中,以下命令应该处理它。 It all goes down to the following packages.这一切都归结为以下软件包。

(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

Shapely loads geos via ctypes . 匀称地通过 ctypes 加载地理信息

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.如果它不起作用,那么您的 geos 安装可能搞砸了。 According to this , your geos should be in /usr/lib/libgeos_c.so.1 . 据此,您的 geos 应该在/usr/lib/libgeos_c.so.1中。 Is your library actually there?你的图书馆真的在那里吗?

在 Fedora 上安装 geos 和 geos-devel

sudo yum install geos geos-devel

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

brew install geos

只是这个安装解决了我的问题。

I had no problem on Jupyter Notebook but when I used PyCharm I encountered this issue.我在 Jupyter Notebook 上没有问题,但是当我使用 PyCharm 时遇到了这个问题。 Tried multiple things windows on machine and the below troubleshooting steps fixed the issue在机器上尝试了多个窗口,以下故障排除步骤解决了该问题

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转到 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 相同

在此处输入图像描述

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 shapely as I am pointing to Anaconda directory from PyCharm.在故障排除过程中,当我从 PyCharm 指向 Anaconda 目录时,我还卸载并重新安装了conda install shapely Hope it helps.希望能帮助到你。

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

I am using Linux (Red Hat) and I got this error:我正在使用 Linux (Red Hat),我收到了这个错误:

OSError: /home/[user]/.conda/envs/ox/lib/libgeos_c.so: cannot open shared object file: No such file or directory OSError:/home/[user]/.conda/envs/ox/lib/libgeos_c.so:无法打开共享对象文件:没有这样的文件或目录

What works for me:什么对我有用:

conda install geos

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

If you have macos , you should run:如果你有macos ,你应该运行:

brew install geos

Source distributions源分布

If you want to build Shapely from source for compatibility with other modules that depend on GEOS (such as cartopy or osgeo.ogr) or want to use a different version of GEOS than the one included in the project wheels you should first install the GEOS library, Cython, and Numpy on your system (using apt, yum, brew, or other means) and then direct pip to ignore the binary wheels.如果您想从源代码构建 Shapely 以与依赖于 GEOS 的其他模块(例如 cartopy 或 osgeo.ogr)兼容,或者想使用与项目轮子中包含的版本不同的 GEOS 版本,您应该首先安装 GEOS 库、Cython 和 Numpy(使用 apt、yum、brew 或其他方式),然后直接 pip 忽略二进制轮子。

pip install shapely --no-binary shapely

If you've installed GEOS to a standard location, the geos-config program will be used to get compiler and linker options.如果您已将 GEOS 安装到标准位置,则 geos-config 程序将用于获取编译器和链接器选项。 If geos-config is not on your executable, it can be specified with a GEOS_CONFIG environment variable, eg:如果 geos-config 不在您的可执行文件上,可以使用 GEOS_CONFIG 环境变量指定它,例如:

GEOS_CONFIG=/path/to/geos-config pip install shapely

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM