0

I have a python package called CoreCode which I have compiled using clr.CompileModules() in IronPython 2.7.5. This generated a file called CoreCode.dll. I then import this dll into my IronPython module by using clr.AddReference(). I know the dll works because I have successfully tested some of the classes as shown below. However, my problem lies with the Base_Slice_Previewer class. This class makes use of Image and ImageDraw from PIL in order to generate and save a bitmap file.

I know the problem doesn't lie with PIL because the package works perfectly well when run in Python 2.7. I'm assuming that this error is coming up because IronPython can't find PIL but I'm not sure how to work around this problem. Any help will be much appreciated.

CoreCode file structure

Code to create the dll

import clr
clr.CompileModules("CoreCode.dll", "CoreCode\AdvancedFileHandlers\ScannerSliceWriter.py", "CoreCode\AdvancedFileHandlers\__init__.py", "CoreCode\MarcamFileHandlers\MTTExport.py", "CoreCode\MarcamFileHandlers\MTTImporter.py", "CoreCode\MarcamFileHandlers\__init__.py", "CoreCode\Visualizer\SlicePreviewMaker.py", "CoreCode\Visualizer\__init__.py", "CoreCode\Timer.py", "CoreCode\__init__.py")

Test for Timer.py

>>> import clr
>>> clr.AddReference('CoreCode.dll')
>>> from CoreCode.Timer import StopWatch
>>> stop_watch = StopWatch()
>>> print stop_watch.__str__()
0:00:00:00 0:00:00:00
>>>

Test for MTTExport.py

>>> from CoreCode.MarcamFileHandlers.MTTExport import MTT_Layer_Exporter
>>> mttlayer = MTT_Layer_Exporter()
>>> in_val = (2**20)+ (2**16) + 2
>>> bytes = mttlayer.write_lf_int(in_val, force_full_size=True)
>>> print "%s = %s" %(bytes, [hex(ord(x)) for x in bytes])
à    ◄ ☻ = ['0xe0', '0x0', '0x0', '0x0', '0x0', '0x11', '0x0', '0x2']
>>>

Test for SlicePreviewMaker.py

>>> from CoreCode.Visualizer.SlicePreviewMaker import Base_Slice_Previewer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "CoreCode\Visualizer\SlicePreviewMaker", line 1, in <module>
ImportError: No module named Image

>>>
BeeLabeille
  • 174
  • 1
  • 4
  • 16
  • How does the import statement in SlicePreviewMaker looks like? I guess it's `import Image`, but have you tried `from PIL import Image` ? – Michiel Overtoom Sep 24 '15 at 09:39
  • @MichielOvertoom at the moment the import statement looks like this: `import os, Image, ImageDraw, ImageFont` When I try `>>> from PIL import Image` I get `Traceback (most recent call last): File "", line 1, in ImportError: No module named PIL` However, when I start typing the intellisense shows PIL in the list of selectable modules. – BeeLabeille Sep 24 '15 at 10:28
  • I guess it's a path-related issue. If the directory in which PIL or pillow resides is in `sys.path`, then `import Image` will work. That's something you can try. On my system, `import Image` will not work, but if I first do `sys.path.append("/Library/Python/2.7/site-packages/PIL")`, it works. On your system the site-packages path is probably different. You could try searching for a directory name containing 'site-packages' in your sys.path list, then tack '/PIL' on it, and append it to sys.path, before imorting Image. – Michiel Overtoom Sep 24 '15 at 15:39
  • @MichielOvertoom I have tried what you suggested and the 'Image' module is imported without error, however i get a new error while actually trying to use it `>>> sys.path.append('C:\\Python27\\Lib\\site-packages\\PIL') >>> import Image >>> myim = Image.new('RGB', (470,470), (86,0,255)) Traceback (most recent call last): File "", line 1, in File "C:\Python27\Lib\site-packages\PIL\Image.py", line 1763, in new File "C:\Python27\Lib\site-packages\PIL\Image.py", line 37, in __getattr__ ImportError: The _imaging C module is not installed >>>` – BeeLabeille Sep 25 '15 at 09:43
  • The fact that you get the error only after trying to use the module, is because Pillow uses lazy-loading. The real error is *'The _imaging C module is not installed'*, probably IronPython can't find this binary because it's not on the PATH or something. You're not the only one with this problem, a Google search tells me. You might want to check out http://stackoverflow.com/questions/4011705/python-the-imagingft-c-module-is-not-installed and http://www.lfd.uci.edu/~gohlke/pythonlibs/ – Michiel Overtoom Sep 25 '15 at 10:38

0 Answers0