简体   繁体   中英

How to copy image to PowerPoint using Python 3.6?

Seems fairly straight forward but whenever I try to merely import the module I get this:

  from pptx.util import Inches
  from pptx import Presentation


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pptx\parts\image.py in <module>()
     12 try:
---> 13     from PIL import Image as PIL_Image
     14 except ImportError:

~\AppData\Local\Continuum\anaconda3\lib\site-packages\PIL\Image.py in <module>()
     59     # and should be considered private and subject to change.
---> 60     from . import _imaging as core
     61     if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-82a968e5e132> in <module>()
----> 1 from pptx.util import Inches
      2 from pptx import Presentation

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pptx\__init__.py in <module>()
     11 del sys
     12 
---> 13 from pptx.api import Presentation  # noqa
     14 
     15 from pptx.opc.constants import CONTENT_TYPE as CT  # noqa: E402

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pptx\api.py in <module>()
     15 
     16 from .opc.constants import CONTENT_TYPE as CT
---> 17 from .package import Package
     18 
     19 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pptx\package.py in <module>()
     14 from .opc.packuri import PackURI
     15 from .parts.coreprops import CorePropertiesPart
---> 16 from .parts.image import Image, ImagePart
     17 from .parts.media import MediaPart
     18 from .util import lazyproperty

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pptx\parts\image.py in <module>()
     13     from PIL import Image as PIL_Image
     14 except ImportError:
---> 15     import Image as PIL_Image
     16 
     17 from ..compat import BytesIO, is_string

ModuleNotFoundError: No module named 'Image'

Can anyone help me to overcome this error, or possibly show me a better library to accomplish this? I'm more than happy to provide any info that would help someone to help me debug this.

I know very little on the modules. Aside from using anaconda prompt, I know nothing.

According to error message, you don't have PIL (or similar) package.
Using your conda package manager you can install Pillow which is a PIL fork and use the same import-name.

conda install -y pillow

Update The best you can try is use conda packages when you use Anaconda/Miniconda if them are available. In this case, I recommend install both with conda manager.

conda install -y -c conda-forge pillow python-pptx

Use conda-forge channel because python-pptx is available.

Fresh Install worked. Here is what I think happened in case this happens to someone else. I had python 2.7 installed on an old machine. Got a new machine through work and they ported all my files over. So despite never installing 2.7 on my new machine, I think there was still conflict from the folders that were ported over having 2.7 files.

I deleted everything, fresh install, and then used pip to install pptx. I did this because when I used conda to install pptx I got an error as if it was installing the wrong version of pptx. I'm not going to question anything else. Everything works now so I'm a happy camper :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM