How to install Ghostscript in aws Lambda? - ghostscript

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

Related

How to install solaris (on colab or locally)?

I try since multiple days to install solaris (https://github.com/CosmiQ/solaris) locally, on google colab or on renkulab (https://renkulab.io/). Up to now, without any luck. I tried on all platform different approaches:
Creating a conda environment (as recommended by the authors)
Directly through pip
And also cloning the repository and access the folders and functions directly
All of these approaches failed so far. Mostly there is a wheel building error for GDAL. Which i have installed first. I do not find any proper documentation or other failure descriptions which makes me question myself... Maybe here someone has experience with this library?
I highly appreciate every hint.
Thanks a lot
Colab Setup
I can get it set up in Colab with the following:
First Cell: Install Mamba/Conda
!pip install -q condacolab
import condacolab
condacolab.install()
This will trigger a runtime restart - it does this on purpose.
Second Cell: Install Solaris prerequisites
I'm assuming we want the GPU-enabled version. If not, there is another YAML in the solaris repository for a CPU-only environment.
!wget https://raw.githubusercontent.com/CosmiQ/solaris/main/environment-gpu.yml
!mamba env update -n base -f environment-gpu.yml
Manually restart the runtime after this completes!
Third Cell: Install Solaris
!pip install solaris
That should be it. Following these steps, I could import the module and use the entrypoints, e.g.,
Module import ✅
import solaris
Example entrypoint ✅
!make_masks -h
There were some future deprecation warnings from NumPy about some syntax in the TensorFlow code, but otherwise, seems functional. However, I don't personally use this tool, so I don't know if there is more to verify.

'fop is missing' while installing Erlang using asdf in Mac

I'm getting the below error while trying to install Erlang using ASDF.
fop is missing
using fakefop to generate placeholder pdf file.
What can I do to fix it?
fop is used to generate documentation in PDF format. You probably won't need it, as most of the time it's easier to look up things in the documentation online, either on the official site, http://erlang.org/doc/, or using the alternative interface at https://erldocs.com/.
So you can safely ignore this error message.
Install fop:
https://xmlgraphics.apache.org/fop/
I've never bothered, though.
I have this error when trying to install Erlang 24.0.5. So, I installed the fop dependency:
brew install libxslt fop
But as mentioned this was not the root cause of my installation issue.
So, I run:
export KERL_CONFIGURE_OPTIONS="--without-wx --without-javac"
asdf install erlang <version>
and I was able to finish the erlang install.
References:
https://github.com/asdf-vm/asdf-erlang#osx
https://erlangforums.com/t/erlang-installation-using-kerl-on-mac-m1-openssl-dependency/1306/5

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.

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

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)

jython 2.7 package installation

Jython Package installation issue, using pip
Hi, I have installed Jython2.7 configured with pydev in eclipse neon, also configured python 3.6 package
I am able to install packages for python using pip installer?
pip install "packagename"
Below are some of the packages in python/Lib/Site-packages directory
I was able to install all the packages
How do I use pip installer to install packages for jython?
I tried to install Jip package with
jython install setup.py
The binary File got installed in the Jython/Lib/Site-packages folder
However, I am not able to use it.
where and how do I get Jython package binaries like jip?
Also, Please let me know how to search jython packages?
Also, How to make pip install library packages in jython?
Any other configuration like jython home, etc that should be made?
This answer is going to be really generic but I just recently have slogged my way through the setup for jython/jip/pip and here's roughly what I had to do.
Firstly, I'm running Windows 7 64 Bit from behind a proxy (work machine.)
Had to install jython 2.7.0 instead of 2.7.1 because (I think anyway) 2.7.1 requires admin privileges which I don't have on my work PC.
Pip didn't install correctly during the Jython installation and I spent an obscene amount of time trying to get it installed and functioning as I knew it from my cpython days. NOTE: Just because you get pip installed, doesn't mean you can use any package on a python package repo. As of 2.7.0, Jython doesn't have end to end capability to interpret/compile some libraries that rely on certain python wrappers of native OS function calls. I believe 2.7.1 makes solid progress in the direction of supporting all needed native calls but don't quote me on that. For example, I tried to use wxPython to make a simple GUI to test my jython install. Trying to install it from pip kept causing really non-specific error info that took me a lot of time to figure out that the cause was jython simply couldn't compile the wxPython source so beware.
I had to set environment variables 'http_proxy' and 'https_proxy' in the form of http://proxyhosturl:port and https://proxyhosturl:port respectively to get out from behind the proxies without having to invoke pip with the proxy switch every time I called it.
To actually install pip, have a look here. These instructions are for Python and Linux/Unix but the principle is roughly the same. Just use jython -m instead of python -m and ignore the '$' at the start of each command line.
Also be sure to CD to your python_home/bin folder when invoking the ez_install exe.
If that doesn't work (didn't for me), try using get-pip.py script with these instructions https://pip.pypa.io/en/stable/installing/ (remember jython instead of python etc.). Download it, cd to the download location and follow the noted install steps. Worth noting is about half way down the install instructions where it details installing from local archives (source/binary zip or tar.gz archives of pip and setuptools as better described here: https://packaging.python.org/tutorials/installing-packages/#installing-from-local-archives).
The links to the bin archives of pip and setuptools are here:
https://pypi.python.org/pypi/setuptools
https://pypi.python.org/pypi/pip
It may also be worth making sure that your PATH environment variable has the jython/bin path in the variable value. The jython installer should do this but, again, mine did not.
If all goes well, you should be able to invoke pip with the --version switch and if it prints a line with the installed pip version info then you should be good to go
Another quirky issue I had was I could invoke a function of pip one time and any subsequent times I would get a stack trace ending with something along the lines of an object not having a certain property. I fixed that by finding my temp directory by opening a windows explorer instance and typing %TEMP% in the address bar and hitting enter, it should take you to a subdir of your AppData folder and there you may see a folder with the name of the package you were trying to install and the text "_pip" somewhere in the directory name. Delete the directory and try the pip install command again. I had to do this + invoke pip install pip -U to update my install to the latest version. Then pip began behaving correctly in my instance.
pip search numpy (or your library name) will generate a list of results with the same logic it uses to locate your desired package when you call pip install but, again, just because it returns a matching package doesn't mean it will compile when you install it (numpy doesn't work because of the missing java to C native function calls I described earlier.) The trade off is that you can import code artifacts from Java JAR files in your Jython script files and leverage their functionality with relative ease. Between the public Java APIs available and the python packages that work with the jython interpretor, you can (in my experience) come up with a way to accomplish your task. See the following info on JIP, Maven and IDEs.
IDE and jython integration (Eclipse)
- If you are stuck using Eclipse (like me) it actually has pretty decent support for python development. Install the PyDev plugin for Eclipse from Help -> Install Software. Put in this URL https://marketplace.eclipse.org/content/pydev-python-ide-eclipse, hit tab, and select the PyDev plugin and hit 'finish.'
- Setup the jython interpretor info from Windows -> Preferences -> PyDev. Provide the path to your jython.jar file.
- You should now be able to use File -> New PyDev project to create a basic python project and configure it to use your version of Jython and Java.
Brief Overview of Jip and Maven
- jip is a jython package that is invoked very similarly to pip but instead will download JAR files from the Maven Central Repository instead of python packages from pypi.com, for example. See the install instructions described here. Note the install procedure for a global jip install which differ from just pip install jip. https://pypi.python.org/pypi/jip/
- I never got jip to work exactly as I wished because there's not a ton of documentation on it outside of what I already linked. However, if you install a JAR using jip, you have to go to your project in Eclipse and actually add the JARs themselves to your PYTHONPATH in order for import statements and editing to have intellisense and so that you don't get a classnotfound exception at runtime. See following screen shot.
- There is a JIP config file that you can use similar to the pip config ini file but I have yet to find any exhaustive documentation on it's setup.
Note in the above screen shot the first entry in the External libraries entries. By default, pip places installed packages in that directory so to enable eclipse to find them, you need to also ensure that location is entered.
In Conclusion
- I have more to add to this answer and I will do so as soon as possible. In the meantime, see this example project I've loaded into github.
https://github.com/jheidlage1222/jython_java_integration_example
It shows basic config and how to interface with JARs from python code. I used the apache httpcomponents library as an example. Good luck amigo.

Resources