我有一个Django Web应用程序,我想尝试将其部署到Windows Nano Server Docker容器。该应用程序依赖于几个Windows二进制文件(.exe文件),因此我目前无法将其移植到* nix。它还取决于Pillow库。
我创建了一个以镜像stefanscherer/python-windows:nano
开头的Dockerfile,该镜像似乎只是安装了Python 3.6.4的Nano Server。我有一个PowerShell脚本,该脚本处理设置venv,将文件放置在需要的位置,提取Windows二进制依赖项并将它们放置在正确的位置。
脚本运行pip install -r requirements
,该脚本成功安装了列出的所有软件包。但是,当我的脚本然后运行命令python manage.py migrate
来设置本地数据库时,我在Pillow中收到DLL导入错误:
Setting up database: python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\vt\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\vt\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\vt\venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\vt\venv\lib\site-packages\django\core\management\base.py", line 350, in execute
self.check()
File "C:\vt\venv\lib\site-packages\django\core\management\base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "C:\vt\venv\lib\site-packages\django\core\management\commands\migrate.py", line 60, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\vt\venv\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "C:\vt\venv\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\vt\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\vt\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\vt\venv\lib\site-packages\django\urls\resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "C:\vt\venv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\vt\venv\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\vt\venv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\vt\venv\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\vt\smartclass\smartclass\urls.py", line 13, in <module>
path('', include('faq_video_portal.urls')),
File "C:\vt\venv\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Python\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\vt\smartclass\faq_video_portal\urls.py", line 3, in <module>
from .views.course_views import *
File "C:\vt\smartclass\faq_video_portal\views\course_views.py", line 6, in <module>
from PIL import Image
File "C:\vt\venv\lib\site-packages\PIL\Image.py", line 64, in <module>
from . import _imaging as core
ImportError: DLL load failed: The specified procedure could not be found.
我到处搜索有关此问题的任何详细信息,大多数帖子都指出Pillow 4.0和Python 3.6.0的问题。我的需求文件未指定版本,因此它拉了Pillow 5.3.0。多个帖子只是建议“升级到Python 3.6.1或更高版本,因为它可以解决DLL导入问题,和/或尝试使用Pillow 4.1.1或更高版本”。但是我在3.6.4上。我敢肯定,这个问题是特定于Nano Server的。
再往前看,我发现Pillow的.pyd
文件取决于Visual C ++ 2015运行时中的库,而这些库不包含在Nano Server中。 Nano Server也没有安装程序,因此我不能仅将VC ++运行时安装程序添加到Dockerfile的命令中。 Microsoft网页上建议您只需将必要的.dll
二进制文件复制到Nano Server映像中即可,它应该可以工作,因此我将所有api-ms-crt-...dll
文件都复制到了Nano Server映像中的相同路径中。但是,DLL导入失败仍然会发生。
作为最后的选择,我尝试切换到服务器核心映像(python:3-msservercore
)上的完整Python。失败是因为pip安装Pillow时,显然已决定需要对其进行编译,并且当然容器中没有C编译器环境。
如何进一步诊断和解决Nano Server内发生的导入错误?