Warning: failed to read path from javaldx - python

An error occurs when converting a file using Libreoffice on ubuntu:
CompletedProcess(args=['soffice', '--headless', '--convert-to', 'txt:Text', '/var/www/Project/temp/e4bac2c2e7c04eb79cfa522967a30dd3.docx', '--outdir', '/var/www/Project/temp/'], returncode=77, stdout=b'', stderr=b'javaldx failed!\nWarning: failed to read path from javaldx\n')
Using subprocess:
process = subprocess.run(['soffice', '--headless', '--convert-to', 'txt:Text', path_docx, '--outdir', settings.TEMP_ROOT], stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
~# java --version
openjdk 11.0.6 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

Ok found the solution:
If you are using libreoffice in headless, with a non root user, trying to convert a docx to a pdf, getting this error:
javaldx failed!
Warning: failed to read path from javaldx
Your user doesn't has a home folder set, or the home folder is not writeable. I just switched from calling libreoffice directly to calling it via a shell script like this:
export HOME=/opt/fhir-services && /usr/lib/libreoffice/program/./soffice --headless --invisible --convert-to pdf --outdir /opt/fhir-services /opt/fhir-services/tmp.docx
tomcat8 is the owner of this folder, now the conversion works.

Expanding #wolfmanx's comment: The following worked for me on Ubuntu 18.04
sudo apt-get install libreoffice-java-common default-jre
Especially default-jre was necessary. Moreover: note, that this seems to be "just" a warning. The operation may work in spite of that.

if using python and calling libreoffice through python subprocess, you need to specify HOME directory:
subprocess.run(
[
<conversion command>
],
env={"HOME": <any_path_where_permission_is_granted>},
)

Look under your home directory for a .config directory, look under there for a libreoffice directory, make sure you own it and everything under it:
chown -R yourlogin.yourgroup libreoffice
Worked for me.

Related

command not found when using makefile to run batch file on Windows 10

When I try to run a makefile (type "make test" in terminal) which runs a batch file I get the equivalent error:
cd directory_path && test.bat
/bin/sh: test.bat: command not found
make: *** [makefile:58: test] Error 127
The makefile is:
.PHONY: test
test:
cd directory_path && test.bat
python path/test.py
(I changed names of the batch file, the directory path, etc. to try and make things more generic)
I can manually type "cd directory_path" and then "test.bat" and those both work. This makefile works on other systems. It only doesn't work on mine. I think it is an issue with how I installed Cygwin and how I run "make.exe".
I can use make to compile C code, but I also get an error trying to use make to run python scripts. The makefile from before also has a command for python path/test.py. This also isn't working on my system. If I delete the batch file line, but keep the python command it throws the error:
python path/test.py
make: python: No such file or directory
make: *** [makefile:59: test] Error 127.
I don't understand why it throws the error of no such file or directory since the path leads to the file, and if i put the python script in the same working directory as the makefile then it still can't find it.
Any ideas/solutions on these problems? Thank you!
EDIT:
Doug Henderson:
I started a cmd prompt at the place with the make file and entered all of these commands in
uname -a
CYGWIN_NT-10.0 james-mobl2 3.1.6(0.340/5/3) 2020-07-09 08:20 x86_64 Cygwin
which make
/usr/bin/make
make -v
GNU Make 4.3
Built for x86_64-pc-cygwin
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
which python
which: no python in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)
(I cleaned up the output a little to make it more legible). This and which test.bat are the only commands that failed.
python -V
Python 3.8.5
The change directory changed correctly
which test.bat
which: no test.bat in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)
I added cmd /c test.bat to the makefile and it worked, but I've also had the batch file run on different systems without that addition. I also have a lot batch files in the actual makefile so this solution works but isn't ideal. It also didn't fix the python script not running.
I didn't initially have cmd.exe in my path, but I added it before entering those commands.
I'm not sure what you mean by starting my PATH in bash with /usr/bin;/bin;THE_REST
MadScientist:
I was manually entering it into a Windows Terminal. Is it possible to have Cygwin invoke a Windows command.com shell?
What I did was go to directory that contained the makefile. Open a windows terminal by typing 'cmd' in the address bar. I would then type 'make test'. That obviously led to the issues. I then went through and manually entered the commands I thought the makefile was supposed to invoke. So I entered 'cd directory_path && test.bat'. This ran.
Matzeri:
I don't really know. I'm completely new to POSIX, etc. I'm guessing I'm using Windows style, and judging from other responses, I'm trying to use Cygwin to do a non-POSIX style.
Thank you, everyone for responses!
Make sure cygwin is installed with basic packages --> Some basic packages not installed with cygwin try below link to install some basic package, uninstall the cygwin and install it again with following basic package :
https://wiki.usask.ca/display/MESH/Running+Python+from+the+Cygwin+Terminal#RunningPythonfromtheCygwinTerminal-Cygwin
make sure cygwin's bin folder is added to your environment variable (e.g., C:\cygwin64\bin)
If cmd /c test.bat works then . is probably not in your PATH. Always do ./test.bat when you want to run something in the current directory. Never count on the PATH unless you have set it yourself. Also make sure the file is executable. chmod +x test.bat

Python 3 flask install wkhtmltopdf on heroku

I have a problem to install the wkhtmltopdf binary on my heroku python app (flask).
A year ago (python 2) I already had an issue, but I was able to solve it by first adding the wkhtmltopdf-pack to the requirements and installing it on heroku and then setting the config var to WKHTMLTOPDF_BINARY=wkhtmltopdf-pack. Here is my old thread
Problem now:
I am trying to use the same approach for python 3, but no version of the wkhtmltopdf-pack works, every push gets rejected and I cant install it.
I tried these versions in the requirements:
wkhtmltopdf-pack==0.12.5
wkhtmltopdf-pack==0.12.4
wkhtmltopdf-pack==0.12.3
wkhtmltopdf-pack==0.12.3.0.post1
wkhtmltopdf-pack==0.12.2.4
I get these errors:
No matching distribution
or
error: can't copy 'bin/wkhtmltopdf-pack': doesn't exist or not a regular file
and I remember once it told me there was a SyntaxError and it could not decode something.
Alternative approach:
It seems it is also possible to use a buildpack, so I tried adding a buildpack:
heroku buildpacks:add https://github.com/dscout/wkhtmltopdf-buildpack.git
I see that the buildpack has been added, but there was no installation and there is also no config var for wkhtmltopdf. I dont understand how to trigger the installation, in all documantations for buildpacks its written "add the buildpack and you are ready to go".
Trying to create a PDF gives me a server error here:
OSError: No wkhtmltopdf executable found: "b''"
EDIT:
I managed to install the buildpack:
The push was successful, but no config var has been created and I have no clue what the path to the binary is.
EDIT
I was able to find the files through heroku bash:
app bin dev etc lib lib64 lost+found proc sbin sys tmp usr var
/ $ cd app
~ $ cd vendor
~/vendor $ dir
wkhtmltox
~/vendor $ cd wkhtmltox
~/vendor/wkhtmltox $ dir
lib
~/vendor/wkhtmltox $ cd lib
~/vendor/wkhtmltox/lib $ dir
libwkhtmltox.so libwkhtmltox.so.0 libwkhtmltox.so.0.12 libwkhtmltox.so.0.12.3
~/vendor/wkhtmltox/lib $ exit
Now I tried to all these files but all give an error:
OSError: wkhtmltopdf exited with non-zero code -11. error
Here is how I set the path:
# WKHTMLTOPDF config
if 'DYNO' in os.environ:
print ('loading wkhtmltopdf path on heroku')
MYDIR = os.path.dirname(__file__)
WKHTMLTOPDF_CMD = os.path.join(MYDIR + "/vendor/wkhtmltox/lib/", "libwkhtmltox.so")
else:
print ('loading wkhtmltopdf path on localhost')
MYDIR = os.path.dirname(__file__)
WKHTMLTOPDF_CMD = os.path.join(MYDIR + "/static/executables/bin/", "wkhtmltopdf.exe")
The best approach to get installed wkhtmltopdf on Heroku by getting the binary of wkhtmltopdf for python 3 instead of wkhtmltopdf-pack and you can achieve this by using pydf.
You can install it simply using pip like:
pip install python-pdf
or for Python 2:
pip install python-pdf==0.30.0
Unlike the buildpack based approach pydf installs with the wkhtmltopdf binary included making it very easy to use, and this is the right approach for Heroku.
But if you still want to stick with build-pack wkhtmltopdf, here's another solution you can give it a try:
Via: CLI Installation
$ heroku create --buildpack https://github.com/homelight/wkhtmltox-buildpack.git
Or Manually:
Add the following line to your .buildpacks file
https://github.com/homelight/wkhtmltox-buildpack.git
Please note that this buildpack is only compatible with the cedar-14 stack. You can use heroku stack:set cedar-14 to set the correct stack.
I was able to solve the problem on my own, following my first approach.
I found an other wkhtmltopdf-pack on pypi and added it to my requirements.txt:
wkhtmltopdf-pack-ng==0.12.3.0
Heroku was able to install this pack.
After that I added the config var for wkhtmltopdf:
heroku config:set WKHTMLTOPDF_BINARY=wkhtmltopdf-pack
The installation is now complete. I need to use the correct path now on my app:
if 'DYNO' in os.environ:
print ('loading wkhtmltopdf path on heroku')
WKHTMLTOPDF_CMD = subprocess.Popen(
['which', os.environ.get('WKHTMLTOPDF_BINARY', 'wkhtmltopdf-pack')], # Note we default to 'wkhtmltopdf' as the binary name
stdout=subprocess.PIPE).communicate()[0].strip()
else:
print ('loading wkhtmltopdf path on localhost')
MYDIR = os.path.dirname(__file__)
WKHTMLTOPDF_CMD = os.path.join(MYDIR + "/static/executables/bin/", "wkhtmltopdf.exe")
Thats it.

sbin/start-stop-daemon not able to start python - ubuntu docker container

I have a simple python script which I want to start a daemon-service in background in docker container
/sbin/start-stop-daemon --start --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec 'python /opt/app/uc/monitor/bin/my-application.py'
when I execute this command in a shell I get
/sbin/start-stop-daemon: unable to stat //python /opt/app/uc/monitor/bin/my-application.py (No such file or directory)
However when execute just the below command in shell it works
python /opt/app/uc/monitor/bin/my-application.py
I'm sure the python is installed and all the links have been setup.
Thanks for the help
That error message implies that start-stop-daemon is looking for a file to open (the stat operation is a check before it opens the file) and treating your 'python ... ' argument as if it was a file.
See this example which confirms this. You may need to read the man page for start-stop-daemon, for your Ubuntu version, to check what a valid command would be for your setup.
Simplest solution is probably to create a shell script (say /opt/app/uc/monitor/bin/run-my-application.sh), and put this into it:
#!/bin/bash
python /opt/app/uc/monitor/bin/my-application.py
Be sure to do chmod +x on this file. If python is not found, use which python to find the path to python and use that in the script.
Now try:
/sbin/start-stop-daemon --start --user root --make-pidfile --pidfile /var/lock/subsys/my-application.pid --exec '/opt/app/uc/monitor/bin/run-my-application.sh'

How to prevent command prompt ( windows ) from opening file when typing command?

I download source code of my app from google appengine using this command in cmd:
appcfg.py download_app -A <your_app_id> -V <your_app_version> <output-dir>
But, instead of running the command, it opens the file "appcfg.py". So I don't know what to do now.
Sounds like python files are associated with an editor instead of with the python interpreter.
If so you'll have to change the associations for .py files (found in folder options), or call the python interpreter:
C:\path\to\python appcfg.py download_app -A -V

windows scrapyd-deploy is not recognized

I have install the scrapyd like this
pip install scrapyd
I want to use scrapyd-deploy
when i type scrapyd
i got this exception in cmd:
'scrapyd' is not recognized as an internal or external command, operable program or batch file.
I ran into the same issue, and I also read some opinions that scrapyd isn't available / can't run on windows and nearly gave it up (didn't really need it as I intend on deploying to a linux machine, wanted scrapyd on windows for debug purposes). However, after some research I found a way. As I haven't found any clear instructions on this, I will try to make my answer as detailed as possible, listing all the steps that worked for me.
Assuming you want to run scrapyd on your local machine, you will need two command lines running: The first is used to connect to scrapyd and keeping the connection open, and the second is for deploying and scheduling.
You already pip installed scrapyd.
Create a folder C:\scrapyd and an empty .log file named scrapyd.log in this folder (not sure this step is necessary).
Open your cmd and cd to your Scripts folder inside Python. This is usually something like: C:\Python27\Scripts. Type: python scrapyd
At this point you should see something like that:
2014-03-26 13:57:30+0200 [-] Log opened.
2014-03-26 13:57:30+0200 [-] twistd 13.2.0 (C:\Python27\python.exe 2.7.6) starting up.
2014-03-26 13:57:30+0200 [-] reactor class: twisted.internet.selectreactor.SelectReactor.
2014-03-26 13:57:30+0200 [-] Site starting on 6800
2014-03-26 13:57:30+0200 [-] Starting factory <twisted.web.server.Site instance at 0x0000000003F69208>
2014-03-26 13:57:30+0200 [Launcher] Scrapyd 1.0.1 started: max_proc=16, runner='scrapyd.runner'
If you can open your browser and go to http://localhost:6800 then you're ok. The command line window should stay open in the background as connection will be closed if you'll close it.
On windows explorer navigate to your scrapy project folder and edit the scrapy.cfg file found there: write your deploy target name: [deploy:scrapyd] for instance, and uncomment the url line.
Open a second command line and cd to your scrapy project folder. Type: scrapy deploy -l
Deploy: type: scrapy deploy scrapyd -p project_name (scrapyd is your target). You should get a server response code 200 and an ok status. You can check if deploy was successful also by typing: scrapy deploy -L scrapyd
Scheduling: you need to install curl for windows. Here's how: questions/9507353/steps-to-setup-curl-in-windows
type: curl http://localhost:6800/schedule.json -d project=project_name -d spider=spider_name
Again, you should get an ok status, and in your browser at http://localhost:6800 under jobs you can check whether the job was indeed scheduled.
I hope this helps.
If you install scrapyed-client by using pip install scrapyd-client I suggest try this command:
pip install git+https://github.com/scrapy/scrapyd-client
it worked for me.
thanks to scrapyd-client command not found
For me proposed solution above didn't work.
Below what worked for me: (for scrapy in version 0.24).
Go to C:\Python27\Scripts and create two files:
scrapy.bat
scrapyd-deploy.bat
Edit both files with notepad and paste:
In the scrapy.bat file:
#echo off
c:\Python27\python c:\Python27\Scripts\scrapy %*
In the scrapyd-deploy.bat file:
#echo off
c:\Python27\python c:\Python27\Scripts\scrapyd-deploy %*
Then save these files and restart cmd.
If you have C:\Python27\Python and C:\Python27\Scripts in your PATH then both commands scrapy and scrapyd-deploy should work.
Marcin Rapacz's answer work for me. However, I use anaconda to manage my
python library. So, the files should be in "C:\Program Files (x86)\Anaconda3\Scripts", and content in files should be changed like:
#echo off
"C:\Program Files (x86)\Anaconda3\python.exe" "C:\Program Files
(x86)\Anaconda3\Scripts\scrapyd-deploy" %1 %2 %3 %4 %5 %6 %7 %8 %9

Categories

Resources