简体   繁体   中英

How to change the name or alias a python module

I am using a python app, via django, that requires Pillow, and I have installed it via pip. However, when the framework loads it complains that Pillow is not installed. I can verify this when trying import pillow fails.

If I look at the directory that contains the python modules I see there is no "pillow", but there is "PIL". I understand that pillow is a fork of PIL, and I can import PIL (PIL appears in a list of modules within python >>> help() >>> modules).

Without touching the framework, is there a way to convince the app/django that PIL == pillow. I tried import PIL as pillow in a settings file, but that didn't solve the problem.

Thanks

The answer is in your question:

>>> import PIL as pillow
>>> pillow
<module 'PIL' from '/opt/anaconda3/lib/python3.7/site-packages/PIL/__init__.py'>

Note that you need to add the import line in the module you plan to use it.

Maybe if you put this in your startup code it would work.

import sys
import PIL
sys.modules["pillow"] = PIL

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