Installing libtiff on Windows (Anaconda) doesn't yield working package. Help pls - windows

I have 16-bit data that I want to save to compressed TIFF file using libtiff. I thought it would install the package with (ana)conda and be done with it, but to no avail.
Miniconda finds, downloads and seems to install libtiff 4.0.9, but when trying to import the package it fails to find it.
Using pip (pip install libtiff) I get pylibtiff 0.4.2 installed as well, but when trying to use this to import libtiff I get the following:
Traceback (most recent call last):
File "", line 1, in
File "C:\Prog\Miniconda3\lib\site-packages\libtiff__init__.py", line 20, in
from .libtiff_ctypes import libtiff, TIFF, TIFF3D
File "C:\Prog\Miniconda3\lib\site-packages\libtiff\libtiff_ctypes.py", line 46, in
raise ImportError('Failed to find TIFF library. Make sure that libtiff '
ImportError: Failed to find TIFF library. Make sure that libtiff is installed >and its location is listed in PATH|LD_LIBRARY_PATH|..
There are binaries installed to my \pkgs directory in miniconda, but these are apparently not found by my python environment, even when adding the .dll directory (\Miniconda3\pkgs\libtiff-4.0.9-hb8ad9f9_1\Library\bin) to the system path.
How does one fix this? I tried to download Libtiff source code and to build it under Windows (using cmake and Visual Studio -- unsuccessfully, as my C-building skills are very elementary).
Any suggestions?

Firstly, to solve the problem at hand libtiff is not required -- scikit-image is sufficient. To make things less-than-super-obvious, the default skimage.io.imsave() method seems to prefer working through PIL (note that an exception is made for TIFF). Here it gets a bit tricky, as PIL's support for compressed TIFF files is either flaky, or requires libtiff.
By default, the different plugins are tried (starting with the Python
Imaging Library) until a suitable candidate is found. If not given
and fname is a tiff file, the tifffile plugin will be used.
and
"Beginning in version 5.0.0, Pillow requires libtiff to read or write
compressed files. Prior to that release, Pillow had buggy support for
reading Packbits, LZW and JPEG compressed TIFFs without using
libtiff."
Secondly, if you have to use libtiff don't try and mix the conda and pip packages. They seem to have in my case downloaded different and incompatible versions of the package. [The conda package installs the libtiff binaries, but not a python wrapper for it. Hence, importing libtiff (as suggested by some online documentation) does not work even though the libraries are present]
But back to the solution:
Scikit-image, however, comes with an external tool that saves TIFF files (using ZIP or LZMA compression): skimage.external.tifffile.imsave() -- see http://scikit-image.org/docs/dev/api/skimage.external.tifffile.html
In conclusion: armed with scikit-image, you can save losslessly Zip-compressed 16-bit TIFF files using the following command (shown here with medium Zip-algorithm compression):
skimage.external.tifffile.imsave("Compressed.tif", image, compress=5)

Related

download with pip3 packages for another python release

I own an off grid server (linux x86_64 with python3.8) on which I would like to install pypi packages. Up to now, I download manually each package and dependencies from pypi.org. And it is painful.
I would like to use pip3 download feature which is perfect for my needs ! Except the platform I download from is very different (win_amd64 with python3.6). Since I want to get numpy-1.18.5-cp38-cp38-manylinux1_x86_64.whl, I tried :
pip3 download --verbose --only-binary=:all: --abi=cp38 --platform=manylinux1_x86_64 numpy
And, checking the verbose log, for the line which correspond to the expected wheel, I get a it is not compatible with this Python... Of course it isn't !
How could I force pip3 to download the appropriate .whl file even if it is not the correct one for the platform I download it from ?
If you're passing --abi, you have to also pass the --python-version so pip can build the correct platform tag. This should work (untested):
$ pip3 download --only-binary=:all: --python-version=38 --abi=cp38 --platform=manylinux1_x86_64 numpy
Although admitted, pip download is anything but reliable, e.g. when it comes to resolving environment markers and stuff.

How to install Ghostscript in aws Lambda?

Error Message: Please make sure that Ghostscript is installed", "errorType": "RuntimeError"
import camelot
def pdfToJson(event=None, context=None):
tables = camelot.read_pdf("./week-1-2019-20.pdf")
tables[0].df.to_json("./sample.json")
Installed the dependencies with pip install -t .
But still getting the error.
How can I install the "ghostscript" dependency in my python code?
I haven't tried this myself, but you should be able to do this with a Lambda Layer. You can see an example of how this is done via https://github.com/BearTail/ghostscript-aws-lambda-layer.
Some magic may also be needed to tell camelot that the Ghostscript binary can be found at /opt/bin/gs, as that isn't a normal location for it.
In camelot library communication with Ghostscript done via a low-level C-API interface with ctypes usage. Ghostscript is used to generate images from pdf being processed by the library.
You do not need to install any python binding by yourself, the only requirement is Ghostscript itself. The easiest way to install is to use repositories/CD, on Ubuntu simple as that:
sudo apt-get install -y ghostscript
gs --version

Creating pip package for TensorFlow with GPU support results in 0 byte simple_console_for_windows.zip

After successfully building TensorFlow with GPU support, I'm trying to build the pip package and I'm getting an error saying it can't read the simple_console_for_windows.zip file.
I've confirmed that the file is in C:\tensorflow\bazel-bin\tensorflow\tools\pip_package folder, but it is 0 bytes.
This is my pip build command:
bazel-bin\tensorflow\tools\pip_package\build_pip_package C:/tmp/tensorflow_pkg
This is the full error:
Unzipping simple_console_for_windows.zip to create runfiles tree...
[./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip]
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of ./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip or
./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip.zip, and cannot find ./bazel-bin/tensorflow/tools/pip_package/simple_console_for_windows.zip.ZIP, period.
I'm on Windows 10, using Bazel 0.16.1, Tensorflow 1.11, CUDA 9.2 and CUDNN 7.2.1.
My build command was:
bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
Anyone have an idea what I could try or check to get the pip package to build?
Here is an open issue with workaround. https://github.com/tensorflow/tensorflow/issues/20332
Edit the following file to remove all the lines with ".zip".
bazel-out/x64_windows-opt/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params
Run the following command line to generate the required zip file, which is about 107 MB in my case. The verbose option will list all the files.
external\bazel_tools\tools\zip\zipper\zipper.exe vcC bazel-out/x64_windows-opt/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip #bazel-out/x64_windows-opt/bin/tensorflow/tools/pip_package/simple_console_for_windows.zip-0.params
Now the original pip build command will build a whl.
This is a known issue, and unfortunately its root cause is https://github.com/tensorflow/tensorflow/issues/22390
TF is a big codebase, and when the size of the zip file exceeds 2 GBs, bazel's zipping tools break because they only use zip32.
The ultimate solutions are to contribute a fix to bazel to use zip64, and TensorFlow to lose some weight, the package has grown substantially lately.
However, bazel team was able to give us a workaround.
Only when building the pip package, you should add --define=no_tensorflow_py_deps=true to your bazel command. You will still not be able to build a debug binary, but at least you will be able to build a release binary.

How do I import Zbar into my Python 3.4 script?

I am pretty new to programming, and have never used Zbar before. I am trying to write a simple script that will allow me to import Zbar and use it to decode a barcode image. I already have a script set up to decode text from images that uses Pytesseract and Tesseract OCR, but I need to be able to decode barcodes as well. I have Windows 7 32 bit, and and am using Python 3.4. I have already installed Zbar and have used it from the command line successfully to decode their barcode sample. I have tried using >pip install zbar, but I keep getting the error:
"fatal error C1083: Cannot open include file: 'zbar.h': No such file or directory
error: command 'C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe' failed with exit status 2"
Getting the pytesseract OCR was painless but I have wasted a lot of time on this barcode portion of it, any help or alternatives would be much appreciated.
Seven months later you accepted the best answer, a simple solution for
python3.4+ on Windows OS appeared. A ctypes-based wrapper around the zbar barcode reader, a package named pyzbar. If you are on Linux, you need to install libzbar0 but you said you are using Windows and the zbar library is included as dll with the Windows Python wheels. Today, all you need to do is launch:
pip install pyzbar
References for the package:
https://pypi.python.org/pypi/pyzbar
https://github.com/NaturalHistoryMuseum/pyzbar/
I thought I'd share my explorations and discoveries in relation to this problem, even though #ltadams21 has found a workaround.
The short answer: You can't. The zbar module is only compatible with Python 2. The incompatibilities are at the level of the Python C API, which is deep magic beyond my ken.
There's a bug report for this. In the meantime, use the os.system workaround that #ltadams21 posted, or maybe try zbarlight instead? (I haven't tried it myself, because it says it only reads QR codes, and I need something that reads EAN barcodes.)
The long answer: You can follow along with these steps, which represent my best efforts to get it working, but (spoiler alert) it still won't work at the end.
(Re)install zbar for Windows (zbar-0.10-setup.exe), making sure to tick the "Development Headers and Libraries" option.
Download and extract the zbar Python package (zbar-0.10.tar.bz2).
Open setup.py in your preferred text editor.
Scroll to the bottom, find the line that starts libraries, and insert a new line below it, like so (checking that the path is the same on your system as it is on mine):
libraries = [ 'zbar' ],
include_dirs = ['C:/Program Files (x86)/ZBar/include'],
Open a command prompt inside the extracted package and run python setup.py install.
Observe that the new errors now relate to PyIntObject and PyInt_Type. Discover that these are Python 2-only objects.
If desperate, try to re-#define them to use PyLongObject and PyLong_Type instead. Fail, because of course it's not that easy. Bang head against keyboard (gently).
Give up, and use the os.system workaround that #ltadams21 posted.
Forget wrestling with all of the wrappers. The easiest solution for me was to simply use
import os
os.system(r'D:\Winapps\Zbar\bin\zbarimg.exe -d d:\Winapps\Zbar\Examples
\barcode.png')
Worked instantly. Hope this helps anyone else struggling with that issue.
As of November 2016, there is the package pyzbar. To import Zbar for python3.4+ on Windows OS, all you need to do is launch
pip install pyzbar
This is possible because pyzbar is a ctypes-based wrapper around the zbar library that is included as dll with the Windows Python wheels.
The ZBar for python says you need to have the ZBar library installed for it to work. http://zbar.sourceforge.net/download.html
I found an easy solution for 3.4+. First install pyzbar
pip install pyzbar.
Then the below should work
import pyqrcode
from pyzbar.pyzbar import decode
from PIL import Image
qr = pyqrcode.create("HORN O.K. PLEASE.")
qr.png("horn.png", scale=6)
decode(Image.open('horn.png'))
print(qr.data)

how to tell cpanm Image::Magick about header location?

On OS X cpanm Image::Magick fails with
Magick.xs:60:10: fatal error: 'magick/MagickCore.h' file not found
#include < magick/MagickCore.h>
The file is present though. (That space is from me to have it display here.)
How can I tell cpanm and/or Image::Magick where to find those headers?
(IM is installed from source.)
Workaround: download Module, edit Makefile.PL (add header dir to includes), make, make install as written on the imagemagick homepage.
While the question is rather old, I still ran into this issue recently.
I was able to resolve it with new ImageMagick installed via homebrew (brew install imagemagick which installed version 6.9.5-3), then firing up cpan and installing JCRISTY/PerlMagick-6.89-1.tar.gz package.
It fails in test section. Thus I analysed what tests fails and decided to cheat a bit (I don't need all ImageMagick functions). I manually edited tests files (use look Image::Magick to get into unarchived package) – for me, it was required to completely comment out test for input.miff (reference/filter/Segment.miff) in t/filter.t and tests for MPEG read in t/mpeg/read.t. Then cpan is able to process Image::Magick finally.
I ran my own tests upon set of GIF and PNG images and these are OK. Hope this helps someone.

Resources