rst2odt not showing the third image - python

I'm trying to convert a rst document with images to odt, but rst2odt seems to fail to get the images from the third one.
It worked a year ago and I guess there must be some upgrade that has changed former behavior.
A simple doc that reproduces my problem is:
######
Report
######
First try
.. image:: image.png
Second try
.. image:: image.png
Last try
.. image:: image.png
The last one is missing in odt!
I process it with:
$ rst2odt test.rst test.odt
And I get an odt with just two images. The third is missing. When using --verbose option, I don't get any complain.
By the way, rst2odt version is (Docutils 0.12 [release], Python 2.7.9, on linux2)
Trying different tips, I've reinstalled python-imaging package and upgraded pillow with no luck
Curiously enough, rst2pdf is able to place the three images properly.
Any help would be highly appreciated since I have a considerable number of rst with a bunch of images, to translate into odt
EDITED: I've purged docutils from my system (Debian Jessie) and then reinstalled without improvement.

Maybe too late but...
I guess that this is because draw:name attributes in ODT outputs (content.xml) generated by rst2odt is set to fixed strings ("graphics2", etc.) and my experimental patch changes this behavior seems to work as far as I tested.
see also: https://bugzilla.redhat.com/show_bug.cgi?id=1360651
the patch: https://bugzilla.redhat.com/attachment.cgi?id=1248317

I don't think this is necessarily the answer you want, but pandoc seems to do a good job here:
pandoc -f rst -t odt in.rst -o out.odt
I think this is really an outstanding bug in rst2odt, and not the only one (see the python 3 latin-1 to utf-8 encode bug), and it doesn't seem that docutils is as well-maintained as it used to be.

Related

Python node2vec (Gensim Word2Vec) "Process finished with exit code 134 (interrupted by signal 6: SIGABRT)"

I am working on node2vec in Python, which uses Gensim's Word2Vec internally.
When I am using a small dataset, the code works well. But as soon as I try to run the same code on a large dataset, the code crashes:
Error: Process finished with exit code 134 (interrupted by signal 6: SIGABRT).
The line which is giving the error is
model = Word2Vec(walks, size=args.dimensions,
window=args.window_size, min_count=0, sg=1,
workers=args.workers, iter=args.iter)
I am using PyCharm and Python 3.5.
What is happening? I could not find any post which could solve my problem.
You are almost certainly running out of memory – which causes the OS to abort your memory-using process with the SIGABRT.
In general, solving this means looking at how your code is using memory, leading up to and at the moment of failure. (The actual 'leak' of excessive bulk memory usage might, however, be arbitrarily earlier - with only the last small/proper increment triggering the error.)
Specifically with the usage of Python, and the node2vec tool which makes use of the Gensim Word2Vec class, some things to try include:
Watch a readout of the Python process size during your attempts.
Enable Python logging to at least the INFO level to see more about what's happening leading-up to the crash.
Further, be sure to:
Optimize your walks iterable to not compose a large in-memory list. (Gensim's Word2Vec can work on a corpus of any length, iuncluding those far larger than RAM, as long as (a) the corpus is streamed from disk via a re-iterable Python sequence; and (b) the model's number of unique word/node tokens can be modeled within RAM.)
Ensure the number of unique words (tokens/nodes) in your model doesn't require a model larger than RAM allows. Logging output, once enabled, will show the raw sizes involved just before the main model-allocation (which is likely failing) happens. (If it fails, either: (a) use a system with more RAM to accomdate your full set of nodes; or (b) or use a higher min_count value to discard more less-important nodes.)
If your Process finished with exit code 134 (interrupted by signal 6: SIGABRT) error does not involve Python, Gensim, & Word2Vec, you should instead:
Search for occurrences of that error combined with more specific details of your triggering situations - the tools/libraries and lines-of-code that create your error.
Look into general memory-profiling tools for your situation, to identify where (even long before the final error) your code might be consuming almost-all of the available RAM.
If you're running macOS v10.15 (Catalina), this might help you.
For me, I started seeing this error right after the upgrade to Catalina.
Execute the following commands one by one in Terminal, and you should be good:
brew update && brew upgrade && brew install openssl
cd /usr/local/Cellar/openssl/1.0.2t/lib
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib/
cd /usr/local/lib
mv libssl.dylib libssl_bak.dylib
mv libcrypto.dylib libcrypto_bak.dylib
sudo ln -s libssl.1.0.0.dylib libssl.dylib
sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib
I found this in one of the Apple forums (but I can't seem to recollect exactly where).
Also, some blessed soul has also written a batch for this.
It can be found in this gist.
I had the same issue, and finally, I figured it out. The reason for me was my Keras version 2.2.0 was too high.
After I changed the version to 2.0.1, it worked.
For me the problem was with the Snowflake connector Python library running on macOS v10.15 (Catalina).
I found the solution from user VikR in a blog post given in answer 59538581 that has been deleted from this page: Python Abort trap: 6 fix after Catalina update by Danny Bryant. It explains that the SSL libraries need to be placed back into your Mac's operating system path and gives the steps to do it. It also lists the steps to upgrade your libraries using brew and pip3.
Here are the steps that I followed to get my Python script running again.
brew update
brew upgrade
cd /usr/local/lib
ln -s /usr/local/Cellar/openssl\#1.1/1.1.1j/lib/libssl.1.1.dylib libssl.dylib
ln -s /usr/local/Cellar/openssl\#1.1/1.1.1j/lib/libcrypto.1.1.dylib libcrypto.dylib
pip3 install --upgrade snowflake-connector-python
For me I did not have to install OpenSSL as I had already installed it. Please read Bryant's page for more detail.
Note that
My version of OpenSSL is of course later than Bryant's instructions. Your version will most likely be later, too, compared to what I used here.
The Homebrew /Cellar/ directory structure was slightly different for me versus when Bryant wrote his instructions. It may have changed again when you read this.
I chose to link the libraries directly rather than linking to copies of the libraries, as Bryant did.
My Homebrew /Cellar/ and /usr/local/lib folders actually needed a fair amount of user ownership changes. Since that wasn't related to the original question, I omitted those steps.
Use:
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'

How to ensure that README.rst is valid?

There are two version of my little tool:
https://pypi.python.org/pypi/tbzuploader/2017.11.0
https://pypi.python.org/pypi/tbzuploader/2017.12.0 Bug: The pypi page looks ugly.
In the last update a change in README.rst cases a warning:
user#host> rst2html.py README.rst > /tmp/foo.html
README.rst:18: (WARNING/2) Inline emphasis start-string without end-string.
README.rst:18: (WARNING/2) Inline emphasis start-string without end-string.
Now the pypi page looks ugly :-(
I use this recipe to do CI, bumpversion, upload to pypi: https://github.com/guettli/github-travis-bumpversion-pypi
How could I ensure that no broken README.rst gets released any more? With other words I want to avoid that the pypi page looks ugly.
Dear detail lovers: Please don't look into the current particular error in the README.rst. That's is not the question :-)
Update
As of Sep 21, 2018, the Python Packaging Authority recommends an alternative command twine check. To install twine:
pip install twine
twine check dist/*
Note that twine requires readme_renderer. You could still use readme_renderer, and you only need to install twine if you want its other features, which is a good idea anyway if you are releasing to PyPI.
From the official Python packaging docs, Uploading your Project to PyPI:
Tip: The reStructuredText parser used on PyPI is not Sphinx! Furthermore, to ensure safety of all users, certain kinds of URLs and directives are forbidden or stripped out (e.g., the .. raw:: directive). Before trying to upload your distribution, you should check to see if your brief / long descriptions provided in setup.py are valid. You can do this by following the instructions for the pypa/readme_renderer tool.
And from that tool's README.rst:
To check your long description's locally simply install the readme_renderer library using:
$ pip install readme_renderer
$ python setup.py check -r -s
Preamble
I had a readme which would not render on PyPi, other than the first element on the page (an image). I ran the file against multiple validators, and tested it against other renders. It worked perfectly fine everywhere else! So, after a long, nasty fight with it, and numerous version bumps so I could test a PyPi revision, I tried reducing the file to a bare minimum, from which I'd build it back up. It turned out that the first line was always processed, and then nothing else was...
Solution
Discovering this clue regarding the first line, I then had an epiphany... All I had to do was change the line endings in the file! I was editing the file in Windows, with Windows line endings being tacked on implicitly. I changed that to Unix style and (poof!) PyPi fully rendered the doc!
Rant...
I've encountered such things in the past, but I took it for granted that PyPi would handle cross platform issues like this. I mean one of the key features of Python is being cross platform! Am I the first person working in Windows to encounter this?! I don't appreciate the hours of time this wasted.
You could try if rstcheck catches the type of error in your readme. If it does, run it after pytest in your script section. (and add it in your requirements ofc).

Python OpenCV 3.2 imshow() no image content with waitKey(0)!

I installed OpenCV3.2 + python3.6.1 from this installation guide. (For the paths needed in guide I typed:
Edit: I'm not sure, but I guess that I should install opencv under 3.6, not 3.6.1, please don't use my paths for your installation!
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin/libpython3.6.dylib
and
ls -d /usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/include/python3.6m/)
My testing code is completely the same as the tutorial of OpenCV 3.2 documentation, but the output screen show nothing but a title:
import numpy as np
import cv2
img = cv2.imread('1.jpg',0)
cv2.imshow('image', img)
cv2.waitKey(0)
The result:
As the picture shown the content of the image is missing.
and it seems that it has something to do with my python, the icon is broken:
Please help me! I just want to use opencv for my school project...
If you just encounter the same problem, I can solve your problem. But you should take a look before you follow any further steps:
I will recommend you first delete OpenCV 3.2 from your mac.
Don't know how to delele? Here are the steps:
Read this answer first if you want to know what the following command do in details, then run the following command in your Terminal:
$> sudo find / -name "*opencv*" -exec rm -i {} \;
Please read every delete-checking message carefully, or you may delete some of your files containing "opencv" in filename, which may not related to OpenCV but may be your personal files.
Your cv2.so will still alive somewhere in your disk, go checkout where it is with the following command in Terminal:
$> ls -l /usr/local/lib/python3.6/site-packages/
In my case I found the cv2.so at .../python3.6/..., you should press 'tab' at /usr/local/lib/python then check out the site-packages folder for each python version (,which maybe you're about to re-install the OpenCV,) to search cv2.so. if you found it, delete it.
Install OpenCV3.2 with Homebrew for Python2.7 / 3.6. Just follow all the steps, and keep in mind that Homebrew is your best friend.
Edit: The link works for both Python2.7 and 3.6.
I ran into a similar issue but on the C++ API perspective. Credits go out to mattmyne.
Window autosize was not working for macOS using cocoa. The window's image dimensions could not be found. This has been fixed by removing IP64 specific synthesize in window_cocoa.mm that was causing null reference for the window's contentView image property in cvShowImage (image reference was not linked to _image).
In a nutshell, OpenCV tried to support both 32 and 64-bit ObjC compilers but since Apple no longer supports 32-bit, some image synthesizing operations resulted in null references in 64-bit machines. More info
To resolve this, locate the file window_cocoa.mm; if built from source it'll be in opencv/modules/highgui/src.
Change this
#implementation CVView
#if defined(__LP64__)
#synthesize image;
#else // 32-bit Obj-C does not have automatic synthesize
#synthesize image = _image;
#endif
To this
#implementation CVView
#synthesize image = _image;
Do the same thing for the CVWindow and CVSlider implementations to accommodate videos as well.
Recompile OpenCV and test out your code.

Python / Elaphe generates broken barcodes

I am trying to generate code128 barcodes using Python/Elaphe, which is based on Barcode Writer In Pure Postscript (BWIPP). Strangely, the barcodes generated by Elaphe don't match the ones generated by BWIPP and do not conform to code 128 standard.
In particular, I tried a simple example, the generation of a barcode for the letter 'A' (capital A):
from elaphe import barcode
b = barcode('code128', 'A')
b.show()
That works just fine, but the generated barcode is missing the right part. It is 35 pixels wide, where it should be 46. The left part of the barcode matches the one generated by BWIPP and every other code128 generator - it's only the right section that is missing.
Anyone know what's wrong?
(Using elaphe 0.6.0 with python 2.7.10 on Kubuntu 15.10)
See this bug report:
https://bitbucket.org/whosaysni/elaphe/issues/84/code-128-generation-produces-unreadable
It seems that this bug is fixed in the current source version, also the bug is still marked as new.
The the patch which fixed this bug imho:
https://bitbucket.org/whosaysni/elaphe/commits/19dd8f58c76ac75914e3e4d8ae7db1b9489cbcb8?at=develop
This patch is from the 2014-10-22, the current version elaphe 0.6.0 on pypi is from 2013-12-05. If you installed via pip you have the buggy version.
There is a python3 enabled fork of this project https://pypi.python.org/pypi/elaphe3, which was uploaded on the 2016-05-25. So this fork might contain the necessary bugfix. You could remove elaphe and install elaphe3.
However, considering that elaphe (at least the non 3 version) looks pretty abandoned and has GhostScript and PIL as dependencies I would look for another solution.

Bad Marshal error -- runsnake

I ran cProfile on a python 3 script, worked nicely, then tried to visualize it using runsnake. Howvever, I got an empty screen and the error 'bad marshal data'.
I removed .pyc file but that did not work either.
The code I used to install runsnake was:
sudo apt-get install python-profiler python-wxgtk2.8 python-setuptoolD
sudo easy-install installSquareMap RunSnakeRun
I am using UBUNTU.
Many thanks.
note: I should add I installed everything while py3k was activated
TL;DR: This error occurs when profiling in Python 2.x and viewing the profile in Python 3.x or vice versa.
I had the same problem. As far as I can tell, the RunSnakeRun package has not been ported to Python3. At least, I could pip it to python2 but not to python3 (SyntaxError). Further, I think the output format of cProfile is not compatible between python 2/3. I did not take the time to find an definitive confirmation of this, but in the doc of cProfile class pstats.Stats(*filenames, stream=sys.stdout), they do say "The file selected by the above constructor must have been created by the corresponding version of profile or cProfile. To be specific, there is no file compatibility guaranteed with future versions of this profiler, and there is no compatibility with files produced by other profilers.". This seems to be the origin of your problem. For e.g., I made a profile output from python3
import cProfile
cProfile.run('some code to profile', 'restats')
and tried to open it in RunSnakeRun and got the same marhsal error you got. Further, if I do
import pstats
p = pstats.Stats('restats')
p.strip_dirs().sort_stats(-1).print_stats()
in python3, it works like a charm. If I do it in python2, it gives the marshal error. Now, RunSnakeRun is executed in python2 (unless you found some way to make it run in python3). So, my guess is that you have performed your profiling in python3 and are using tools relying on python2 to analyze them, which tools are expecting the output to be compatible with python2.
The RunSnakeRun project seems to be inactive for a while now (copyright on the home page is 2005-2011) and there is no indication that it will be ported to python3.... Maybe considering alternative visualization tool might be the best way to go for you if you want to develop in Python3. pyprof2calltree in combination with KCachegrind worked fine for me in Linux. It can provide a similar visual view of the profiling output as you would get from RunSnakeRun.
Also ran into the same problem and I think there's no (good) way to use runsnake for Python3 (as it already was mentioned in the previous answer). However, SnakeViz might help. It's a relatively intuitive graphical overview of profiling data that, like runsnake, builds on top of profile outputs. Nice bonus: works also for Jupyter notebooks!

Categories