无法在Python中导入gdal?
我在 Ubuntu Jaunty 上安装并运行了 gdal
,但无法运行 gdal2tiles
,因为出现错误:
Traceback (most recent call last):
File "/usr/local/bin/gdal2tiles.py", line 42, in <module>
import gdal
ImportError: No module named gdal
当我打开 python 并输入 import gdal
时> 我遇到同样的错误。
我已将 LD_LIBRARY_PATH 设置为 /usr/local/lib
(不带空格!),但它似乎没有任何区别。
看起来 Python 找不到 gdal
。有人可以帮忙吗?
谢谢!
I have gdal
installed and running on Ubuntu Jaunty but I can't run gdal2tiles
because I get the error:
Traceback (most recent call last):
File "/usr/local/bin/gdal2tiles.py", line 42, in <module>
import gdal
ImportError: No module named gdal
When I open python and type import gdal
I get the same error.
I've set LD_LIBRARY_PATH
(without spaces!) to /usr/local/lib
but it doesn't seem to have made any difference.
Looks like Python can't find gdal
. Can anyone help?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎是一个“Python 路径”问题。在定义的路径中查找 Python 库。尝试
如果gdal.py和相关文件所在的目录不在这个列表中,那么Python找不到它。这是“诊断”部分。要解决这种情况,您有多种选择......它们都取决于了解 Python 用于构建此路径的规则。
我在“官方”中看到了与先前描述的 sys.path 构建相关的规则的唯一地方Python 文档位于 教程 的第 6.1.2 节
摘录:
Ith seems to be a "Python Path" issue. Python libraries are looked-up within a defined path. Try
If the directory where the gdal.py and related files is not in this list, then Python cannot find it. That's for the "diagnostics" part. To fix the situation, you have several options... They all hinge on knowing the rules which Python uses to build this path.
The only place where I've seen the rules pertaining to the building of sys.path formerly described, within the "official" Python documentation, is in the tutorial, at section 6.1.2
Excerpt:
我也遇到了同样的问题。但我发现这可能是因为包名称与“gdal”不同。
我使用命令“conda install -c conda-forge gdal”在我的anaconda环境中安装了gdal,
然后尝试通过python脚本“import gdal”或“from osgeo import gdal”导入gdal。没用。
我查看了这个包的地址“.../anaconda3/envs/(环境名称)/lib/python3.7/site-packages”,并复制了原来的包目录,并将名称从“GDAL-3.4.7”更改为“GDAL-3.7”。 1-py3.7-linux-x86_64.egg-info”到“gdal”。
更改包名称
然后我发现它有效。我通过“import gdal”成功导入了gdal。
I met the same problem as well. But I found it might because the package name is not as same as "gdal".
I installed gdal in my anaconda environment using command "conda install -c conda-forge gdal",
then I tried importing gdal by python scripts "import gdal" or "from osgeo import gdal". Didn't work.
I look into the address of this package ".../anaconda3/envs/(environment name)/lib/python3.7/site-packages", and copied the original package directory, and changed the name from "GDAL-3.4.1-py3.7-linux-x86_64.egg-info" to "gdal".
change package name
Then I found it worked. I succeed in importing gdal by just "import gdal".