【问题标题】:Import pillow without installing进口枕头免安装
【发布时间】:2015-04-12 08:48:43
【问题描述】:

我正在开发一个需要 PIL 来显示图像的 Python 项目。但是,我正在使用的计算机通常不允许我安装东西,并且有一个非常简单的 python 设置。出于这个原因,我需要的大部分模块都放在与我的 python 文件相同的目录中。

我尝试对 PIL 做同样的事情。我下载了枕头源,并将 PIL 文件夹复制到我的项目中。然后我可以毫无问题地运行“import PIL”。但是,当我尝试运行“从 PIL 导入图像”时,出现错误:“未安装 _Imaging C 模块”。从其他搜索来看,我认为正确安装 Pillow 可以解决这个问题,但是我希望 PIL 更便携,并且不需要灌输。

任何想法都会很棒。提前致谢。

【问题讨论】:

  • 如果您在构建PIL.egg 文件时遇到问题,或者您可以下载Pillow.egg 文件预制here

标签: python python-3.x python-imaging-library pillow


【解决方案1】:

一种解决方案是将PIL.egg 形式的脚本捆绑在一起。然后,您可以直接从.egg 导入PIL,而不必安装它:

How to create Python egg file

基本流程如下:

如何制作鸡蛋:

  1. 编辑 PILsetup.py 以包含 from setuptools import setup 而不是正常的设置导入
  2. 运行python setup.py bdist_egg
  3. 鸡蛋会在dist/里面

如何导入鸡蛋:

.egg 文件复制到脚本目录并导入所需模块:

import os
import sys

DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(DIR, "./path/to/PIL.egg"))

#You can now import from PIL normally:
from PIL import Image

【讨论】:

  • 我试过这样做,使用从 PyPi 下载的枕头蛋。但是,使用您的脚本时,出现以下错误: File "C:\Users\USER\Documents\Python\PIL test\p import.py", line 8, in from PIL import Image File pil egg file ,第 63 行,在 from PIL import _imaging as core 文件 pil egg 文件,第 7 行,在 bootstrap 文件 pil egg 文件,第 6 行,ImportError: DLL load failed: % 1 不是有效的 Win32 应用程序。
猜你喜欢
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-11
  • 2015-12-17
  • 2021-05-24
相关资源
最近更新 更多