Runtime error in build_pdf module of latex - python - python

Below is my latex_template.py file
min_latex = (r"\documentclass{article}"
r"\begin{document}"
r"Hello, world!"
r"\end{document}")
from latex import build_pdf
# this builds a pdf-file inside a temporary directory
pdf = build_pdf(min_latex)
# look at the first few bytes of the header
print bytes(pdf)[:10]
When I try to run this file I get the following error:
python latex_template.py
Traceback (most recent call last):
File "latex_template.py", line 9, in <module>
pdf = build_pdf(min_latex)
File "/home/psycane/test/venv/local/lib/python2.7/site-packages/latex/build.py", line 205, in build_pdf
raise RuntimeError('No available builder could be instantiated. '
RuntimeError: No available builder could be instantiated. Please make sure LaTeX is installed.
Please help!

It seems like your're missiing the latex binaries.
On linux machines it's calles texlive --> More infos
For example Ubuntu:
sudo apt-get install texlive
For OSX you can install MacTex

If your system is ubuntu or debian, the solution is below.
sudo apt-get install latexmk
If your system is other linux distribution, you need to find solution to install "latexmk" by yourself.
You must haven't installed "latexmk" judged by "bool(which(self.latexmk))" in the following source code.You can test it in cmd tools with the cmd "which latexmk"
def build_pdf(source, texinputs=[]):
"""Builds a LaTeX source to PDF.
Will automatically instantiate an available builder (or raise a
:class:`exceptions.RuntimeError` if none are available) and build the
supplied source with it.
Parameters are passed on to the builder's
:meth:`~latex.build.LatexBuilder.build_pdf` function.
"""
for bld_cls in PREFERRED_BUILDERS:
builder = bld_cls()
if not builder.is_available():
continue
return builder.build_pdf(source, texinputs)
else:
raise RuntimeError('No available builder could be instantiated. '
'Please make sure LaTeX is installed.')
def is_available(self):
return bool(which(self.pdflatex)) and bool(which(self.latexmk))
The github link is https://github.com/mbr/latex/blob/master/latex/build.py.

Related

Cannot produce an eps or pdf chart in Python's Plotyl in Ubuntu

I am using the python library called plotly on Ubuntu 18.04 and Python 3.6.
I need to export the graphs as .eps or .pdf files.
I use this sample code:
import plotly.graph_objects as go
import decimal
import plotly
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'
x = ['Product A', 'Product B', 'Product C']
y = [(20/80)*100, (14/80)*100, round(decimal.Decimal(2.256),2)]
# Use textposition='auto' for direct text
fig = go.Figure(data=[go.Bar(
x=x, y=y,
text=y,
textposition='auto',
)])
fig.show()
fig.write_image("fig1.eps")
But the figure is shown in a new tab in the browser. It is not written as eps. Also, in the command line where I run the python file, I see:
/usr/local/lib/python3.6/site-packages/pandas/compat/__init__.py:84: UserWarning:
Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
Traceback (most recent call last):
File "sample.py", line 15, in <module>
fig.write_image("fig1.eps")
File "/usr/local/lib/python3.6/site-packages/plotly/basedatatypes.py", line 2688, in write_image
return pio.write_image(self, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1705, in write_image
fig, format=format, scale=scale, width=width, height=height, validate=validate
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1482, in to_image
ensure_server()
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1344, in ensure_server
validate_executable()
File "/usr/local/lib/python3.6/site-packages/plotly/io/_orca.py", line 1139, in validate_executable
raise ValueError(err_msg)
ValueError:
The orca executable is required in order to export figures as static images,
but the executable that was found at '/usr/bin/orca'
does not seem to be a valid plotly orca executable. Please refer to the end of
this message for details on what went wrong.
If you haven't installed orca yet, you can do so using conda as follows:
$ conda install -c plotly plotly-orca
Alternatively, see other installation methods in the orca project README at
https://github.com/plotly/orca.
After installation is complete, no further configuration should be needed.
If you have installed orca, then for some reason plotly.py was unable to
locate it. In this case, set the `plotly.io.orca.config.executable`
property to the full path of your orca executable. For example:
>>> plotly.io.orca.config.executable = '/path/to/orca'
After updating this executable property, try the export operation again.
If it is successful then you may want to save this configuration so that it
will be applied automatically in future sessions. You can do this as follows:
>>> plotly.io.orca.config.save()
If you're still having trouble, feel free to ask for help on the forums at
https://community.plot.ly/c/api/python
Here is the error that was returned by the command
$ /usr/bin/orca --help
[Return code: -11]
Note that I installed the orca using: pip3 install orca. I also added this line in the code:
plotly.io.orca.config.executable = '/usr/lib/python3/dist-packages/orca'
But this did not result in producing the eps file.
You do not have Orca properly installed. Unfortunately you cannot install Orca with pip. Instead follow Orca's installation method 4: standalone binaries:
Download the .AppImage with wget from Orca's release page. At the time of writing it was: wget https://github.com/plotly/orca/releases/download/v1.2.1/orca-1.2.1-x86_64.AppImage
Follow the Linux install instructions. Make sure you really follow the troubleshooting guides as well (both) - it wasn't easy.

using the iio python package

Hello there fellow Devs :)
I want to listen for the information given by the MMA8452 acceleration sensor with python.
To do this i want to use the libiio package for python.
To install it I manually built it following the instructions given in this guide
It seemed to be installed fine, cuz I have no Problem importing the Package because it is located in my site-packages folder.
However if I want to do the initial step of creating a context with the "iio.context()"-function, I get this error:
Traceback (most recent call last):
File "./bindings/python/examples/iio_info.py", line 89, in <module>
main()
File "./bindings/python/examples/iio_info.py", line 34, in main
ctx = iio.Context(uri)
File "/usr/local/lib/python2.7/dist-packages/iio.py", line 730, in __init__
self._context = _new_default()
File "/usr/local/lib/python2.7/dist-packages/iio.py", line 33, in _checkNull
raise OSError(err, _strerror(err))
OSError: [Errno 2] No such file or directory
Can someone help me get the iio package working?
For my hardware:
I use the Raspberry Pi3 model B, with Raspberian-stretch-lite v4.9
Thanks in advance,
Holger
You should just need to install the libiio python package to be able to use it. In libiio/bindings/python/ run:
$sudo python setup.py install
Here's a little sample script (Python 2.7) that works on my system, since I have an mcp3204 adc with an iio driver loaded. I used 'apt install python-libiio' to install the python bindings for libiio.
#! /usr/bin/python
import time, iio
ctx = iio.LocalContext()
ctrl = ctx.find_device('mcp3204')
voltages = ['voltage0', 'voltage1', 'voltage2', 'voltage3']
for id in voltages:
chan = ctrl.find_channel(id)
print("{0}: {1}".format( chan.id, chan.attrs['raw'].value) )

Error Installing imgseek on Mac Os

I am trying to install imgseek- the server version (http://www.imgseek.net/) to do image analysis.I am able to install all the dependencies successfully using:
sudo port install swig
sudo port install swig-python
sudo easy_install twisted
sudo port install imagemagick
sudo easy_install epydoc
Then I download isk-daemon from the downloads(isk-daemon-0.9.3.tar.gz) and build and install it. Everything runs succesfully.
But when I run iskdaemon.py from the command prompt, i get the following error:
sk-daemon : WARNING | no config file (isk-daemon.conf) found. Looked at local dir, home user dir and /etc/iskdaemon. Using defaults for everything.
root : ERROR Unable to load the C++ extension "_imgdb.so(pyd)" module.
root : ERROR See http://www.imgseek.net/isk-daemon/documents-1/compiling
Traceback (most recent call last):
File "/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/imgSeekLib/ImageDB.py", line 35, in
import imgdb
File "/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/imgSeekLib/imgdb.py", line 28, in
_imgdb = swig_import_helper()
File "/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/imgSeekLib/imgdb.py", line 20, in swig_import_helper
import _imgdb
ImportError: dlopen(/Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/_imgdb.so, 2): Symbol not found: __ZNSs4_Rep20_S_empty_rep_storageE
Referenced from: /Users/gghanakota/anaconda/lib/python2.7/site-packages/isk_daemon-0.9.3-py2.7-macosx-10.5-x86_64.egg/_imgdb.so
Expected in: dynamic lookup
Please help!
I had the same problem when I was trying to install iskdaemon on my Mac (osx yosemite).
The problem in my case was that when I was building it, the c++ compiler threw two errors on using min function in imgdb.cpp
The error was because the types of the variables in the min function were not the same. Consequently the build failed and the imgdb module wasn't produced.
I fixed it by adding a simple typecast to the variables passed to the min function:
I changed: min(sz, numres) to min(sz, (long int)numres) on line 1003,
and min((V.size()/2), numres) to min((int)(V.size()/2), numres) on line 1327
I built again and it is working now.
Check if you get any errors when you build, maybe you are facing the same issue.

pycallgraph with pycharm does not work

I'm using mac os x and trying to setup pycallgraph.
Ive installed pycallgraph with pip and graphviz with homebrew.
Everything works from shell.
But not from pycharm.
from pycallgraph import PyCallGraph
from pycallgraph import Config
from pycallgraph import GlobbingFilter
from pycallgraph.output import GraphvizOutput
config = Config()
config.trace_filter = GlobbingFilter(exclude=[
'pycallgraph.*',
])
graphviz = GraphvizOutput(output_file='filter_exclude.png')
with PyCallGraph(output=graphviz, config=config):
def my_fun():
print "HELLO"
my_fun()
/Users/user/Projects/py27/bin/python /Users/user/Projects/py27_django/test2.py
Traceback (most recent call last):
File "/Users/user/Projects/py27_django/test2.py", line 15, in <module>
with PyCallGraph(output=graphviz, config=config):
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 32, in __init__
self.reset()
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 53, in reset
self.prepare_output(output)
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/pycallgraph.py", line 97, in prepare_output
output.sanity_check()
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/graphviz.py", line 63, in sanity_check
self.ensure_binary(self.tool)
File "/Users/user/Projects/py27/lib/python2.7/site-packages/pycallgraph/output/output.py", line 96, in ensure_binary
'The command "{}" is required to be in your path.'.format(cmd))
pycallgraph.exceptions.PyCallGraphException: The command "dot" is required to be in your path.
Process finished with exit code 1
Here:
/Users/user/Projects/py27/ -> virtualenv dir
/Users/user/Projects/py27_django/ -> project dir
What does it want from me?
Install graphviz in MacOS by using:
brew install graphviz
or in Ubuntu by using:
sudo apt-get install graphviz
Then you can test dot by using:
dot -v
You can also download pkg from here
The answer is:
In menubar:
Pycharm -> Run -> Edit Configurations...
In dialog:
for selected .py file or for Defaults/Python:
Environment field group:
Environment variables > ... -> + ->
Add entry:
Name: PATH
Value: /usr/local/bin
Include print environment variables should be selected
FWIW, this is a behaviour which two other users have filed as an Issue in PyCharm's bugtracker: https://youtrack.jetbrains.com/issue/PY-17816
I'll update this post if the developers comment there.
[Update] On September 22nd 2016, Pycharm developers offered a fix in the Early Access version. https://blog.jetbrains.com/pycharm/2016/09/pycharm-2016-3-eap-is-available-with-initial-support-for-python-3-6/, but this does not seem to have fixed the problem yet.
This process worked for my environment; I got the same "dot" error after I compiled. Unfortunately, I was looking for a visual representation of the code which shows inheritance, function calls, more like a flow chart. On the UP-and-UP, I Understand what a profiler does this one worked great!
Pycharm: 2020.3.3
Python 3.8
PyCallGraph3
Venv Environment in Pycharm
For it to work in PyCharm on Windows 10:
Install the package under your interpreter: pycallgraph3
File > Settings > Project > Python Interpreter
Install the program called GraphViz (https://graphviz.org/)
Under your Run/Debug Configurations go to Environment Variables:
Paste the following line at the end of the massive list
;C:\Program Files\Graphviz\bin;
After here, I didn't test its validity but did it anyway if it didn't work try adding it to your windows path.
In Windows under:
System Properties > Environment Variables
FOR USER WINDOW (TOP)
Edit > PATH > NEW> add Entry: C:\Program Files\Graphviz\bin\
FOR SYSTEM VARIABLES WINDOW (BOTTOM):
Edit > PATH > NEW > add a New Entry: C:\Program Files\Graphviz\bin\

Python bindings for libtorrent-rasterbar are not working

I'm running Debian 6.0.6
I've downloaded latest version of libtorrent-rasterbar from here: http://code.google.com/p/libtorrent/downloads/detail?name=libtorrent-rasterbar-0.16.6.tar.gz&can=2 and installed it:
./configure --enable-python-binding
make
make install
cd bindings/python
python setup.py build
python setup.py install
now I want to test whether the library works:
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libtorrent-rasterbar.so.7: cannot open shared object file: No such file or directory
The packaged version of libtorrent from the distributive's repository had some funny behaviour (complaining on boost dependences), so I've decided to upgrade. The same situation is on both of my debian boxes, yet ubuntu box is fine.
old error message from my debian box:
File "ar.py", line 15, in create
s.start_dht()
Boost.Python.ArgumentError: Python argument types in
session.start_dht(session)
did not match C++ signature:
start_dht(libtorrent::session {lvalue}, libtorrent::entry)
Search for the shared object file and add it to your path.
sudo updatedb
locate libtorrent-rasterbar.so.7
This should output /<path_to_directory>/libtorrent-rasterbar.so.7
Add this to your ~/.profile or temporarily tell Python where to look:
export LD_LIBRARY_PATH=/<path_to_directory>/
See more detailed installation instructions here.

Categories

Resources