python 在 django 下找不到以其他方式找到的库
我刚刚成功安装了 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) ...
I've just successfully installed GeoDjango and all the required libraries. I've set the environment variables and registry keys (yea working under Windows here) and everything works find from the command line.
d:\...\> python
>>> from django.contrib.gis.geos import *
>>> exit()
d:\...\> python manage.py runserver 0.0.0.0
(...)
Now when the server that's being run here encounters the very same line in code it's supposed to execute, it says
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) ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢@ed。和@gddc我找到了解决方案。 Django shell 中也出现了问题。结果我在 Django 设置中设置了 GEOS_LIBRARY_PATH = 'c:\OSGeo4W' ,它应该是 'c:\OSGeo4W\bin' 。调用普通 Python 会忽略这些设置,而是依赖操作系统自身的功能来查找 .dll(成功)。
Thanks to @ed. and @g.d.d.c I found the solution. Problem turned up in the Django shell as well. Turns out I had set GEOS_LIBRARY_PATH = 'c:\OSGeo4W' in my Django settings where it should've been 'c:\OSGeo4W\bin'. Calling plain Python ignored those settings and instead relied on the OS-own functionality to find the .dll (which succeeds).