Django下Python找不到已安装的库

0 投票
1 回答
1262 浏览
提问于 2025-04-17 02:46

我刚刚成功安装了GeoDjango和所有需要的库。我设置了环境变量和注册表键(没错,我是在Windows系统上工作),从命令行一切都运行得很好。

d:\...\> python
>>> from django.contrib.gis.geos import *
>>> exit()
d:\...\> python manage.py runserver 0.0.0.0
(...)

但是,当这里运行的服务器遇到它应该执行的同一行代码时,它却说

WindowsError at /NT/BUAConvex/4DED02804:SQLEXPRESS:44_EU_2011Q2/20187417/
[Error 126] The specified module could not be found

D:\...\views.py in <module>
from django.contrib.gis.geos import * ...

c:\python27\lib\site-packages\django\contrib\gis\geos\__init__.py in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex ...

c:\python27\lib\site-packages\django\contrib\gis\geos\geometry.py in <module>
from django.contrib.gis.geos.coordseq import GEOSCoordSeq ...

c:\python27\lib\site-packages\django\contrib\gis\geos\coordseq.py in <module>
from django.contrib.gis.geos.libgeos import CS_PTR ...

c:\python27\lib\site-packages\django\contrib\gis\geos\libgeos.py in <module>
lgeos = CDLL(lib_path) ...

c:\python27\lib\ctypes\__init__.py in __init__
            self._handle = _dlopen(self._name, mode) ...

1 个回答

0

感谢@ed和@g.d.d.c,我找到了问题的解决办法。这个问题在Django的命令行界面也出现了。原来我在Django的设置里把GEOS_LIBRARY_PATH设置成了'c:\OSGeo4W',其实应该是'c:\OSGeo4W\bin'。直接用普通的Python运行时,它忽略了这些设置,而是依赖操作系统自己去找.dll文件(这样是成功的)。

撰写回答