matplotlib pgf: OSError: No such file or directory in subprocess.py - matplotlib

I try to use matplotlib to create a pgf file for LaTeX:
from matplotlib.pyplot import subplots
from numpy import linspace
x = linspace(0, 100, 30)
fig, ax = subplots(figsize = (10, 6))
ax.scatter(x, x)
fig.tight_layout()
fig.savefig('/home/mark/dicp/python/figure.pgf')
But I get OSError: [Errno 2] No such file or directory:
Traceback (most recent call last):
File "visualize/latex_figs.py", line 32, in <module>
fig.savefig('/home/mark/dicp/python/figure.pgf')
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2220, in print_figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 1957, in print_pgf
return pgf.print_pgf(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 818, in print_pgf
self._print_pgf_to_fh(fh, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 797, in _print_pgf_to_fh
RendererPgf(self.figure, fh),
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 409, in __init__
self.latexManager = LatexManagerFactory.get_latex_manager()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 223, in get_latex_manager
new_inst = LatexManager()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 305, in __init__
cwd=self.tmpdir)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
It also generates this part of the output file:
%% [whole bunch of comments]
\begingroup%
\makeatletter%
\begin{pgfpicture}%
\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{10.000000in}{6.000000in}}%
\pgfusepath{use as bounding box}%
I do not understand what OSError: No such file or directory in subprocesses.py has to do with anything... The file I'm trying to save is writable. Am I misunderstanding something, or is this a bug I should report?

I also had this problem while trying to run the example scripts. The problem occurs where backend_pgf.py first tries to use the default LaTeX command. It seems that the PGF backend assumes that it should use xelatex by default. If the problem is the same for you as for me, then you have two options:
add the key "pgf.texsystem" : "pdflatex" (or lualatex, whatever) to your matplotlib.rcParams. For example, add the following snippet to the top of your script:
import matplotlib
pgf_with_rc_fonts = {"pgf.texsystem": "pdflatex"}
matplotlib.rcParams.update(pgf_with_rc_fonts)
ensure that you have xelatex, and that it is on your PATH, and use that as the default latex command (i.e. assuming you're on a Mac or Linux system, which xelatex should return a path).

Related

Unable to use latex in python plots - RuntimeError: LaTeX was not able to process the following string: b'lp'

I want to use latex for the labels of a figure but I get the error
RuntimeError: LaTeX was not able to process the following string:
b'lp'
Here is the full report generated by LaTeX:
and that is it (I don't see any report)
Edit : Here is the whole error I obtain:
Traceback (most recent call last):
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 197, in __draw_idle_agg
FigureCanvasAgg.draw(self)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1144, in draw
renderer, self, dsu, self.suppressComposite)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2426, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1138, in draw
renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1078, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 967, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 353, in _get_layout
ismath=False)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 230, in get_text_width_height_descent
renderer=self)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 676, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 423, in make_dvi
report))
RuntimeError: LaTeX was not able to process the following string:
b'lp'
Here is the full report generated by LaTeX:
Here is my code:
import numpy as np
from matplotlib import rc
import matplotlib.pyplot as plt
plt.close('all')
rc('text', usetex = True)
mu = np.linspace(0,10,100)
eta = mu**2
fig, ax = plt.subplots()
ax.plot(mu,eta,label= r'$\eta (\mu)$')
ax.set_title('Test')
ax.legend()
I installed MiKTeX, added it to the environment variables according to https://docs.alfresco.com/4.2/tasks/fot-addpath.html.
I checked the packages of MiKTeX, where I found "miktex-dvipng-bin-x64-2.9" in the "\MiKTeX excecutables" category. I deduce I have a dvipng.
I dowloaded Ghostcript, which I also added to the environment variables.
I tried compiling a latex script to pdf using texworks, and it worked just fine, from what I deduce LaTeX is properly installed.
From https://matplotlib.org/1.4.1/users/usetex.html, this is all I was supposed to need...
I tried deleting my .matplotlib/tex.cache directory
I tried writting
import matplotlib as mpl
mpl.rcParams['text.usetex']=True
instead of
from matplotlib import rc
rc('text', usetex = True)
but it yielded the same result.
Swiching
rc('text', usetex = True)
to
rc('text', usetex = False)
prevents the error, but my labels are not written with latex...
After a lot of googling, I'm short with ideas.
Could anyone help me please?
My configuration is:
- Python 3.6 (I run my code in spyder)
- MiKTeX 2.9
- Ghostscript 9.50
- Windows 10
- Edit : matplotlib 2.0.2
Edit : upgrading to matplotlib 3.1.1, I get the following error:
Traceback (most recent call last):
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Vincent\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 209, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 505, in _draw_idle
self.draw()
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
self.figure.draw(self.renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1709, in draw
renderer, self, artists, self.suppressComposite)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 135, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
self._update_title_position(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2556, in _update_title_position
if title.get_window_extent(renderer).ymin < top:
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
ismath="TeX" if self.get_usetex() else False)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
s, fontsize, renderer=self)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
texfile], tex)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
Traceback (most recent call last):
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Vincent\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 209, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 505, in _draw_idle
self.draw()
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
self.figure.draw(self.renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1709, in draw
renderer, self, artists, self.suppressComposite)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 135, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
self._update_title_position(renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2556, in _update_title_position
if title.get_window_extent(renderer).ymin < top:
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
ismath="TeX" if self.get_usetex() else False)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
s, fontsize, renderer=self)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
texfile], tex)
File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
For about the 5th time I unistalled and reinstalled MikTeX, and this time my problem is solved. When running my python script, three windows opened successively asking for packages installations. I attach to this answer screenshots of these three windows. After accepting to install these packages, my script worked just fine. Previously, when unistalling and reinstalling MikTeX, I already saw windows asking for installation and accepted the installations. I don't know why this time it worked whilst it didn't work before...
Anyway, my problem was solved uninstalling and reinstalling MiKTeX, running my script and accepting packages.
Window for installation of a file from type1cm
Window for installation of a file from iftex
Window for installation of a file from zhmetrics

compute() in dask not working

I am trying a simple parallel computation in Dask.
This is my code.
import time
import dask as dask
import dask.distributed as distributed
import dask.dataframe as dd
import dask.delayed as delayed
from dask.distributed import Client,progress
client = Client('localhost:8786')
df = dd.read_csv('file.csv')
ddf = df.groupby(['col1'])[['col2']].sum()
ddf = ddf.compute()
print ddf
It seems fine from the documentation but on running I am getting this :
Traceback (most recent call last):
File "dask_prg1.py", line 17, in <module>
ddf = ddf.compute()
File "/usr/local/lib/python2.7/site-packages/dask/base.py", line 156, in compute
(result,) = compute(self, traverse=False, **kwargs)
File "/usr/local/lib/python2.7/site-packages/dask/base.py", line 402, in compute
results = schedule(dsk, keys, **kwargs)
File "/usr/local/lib/python2.7/site-packages/distributed/client.py", line 2159, in get
direct=direct)
File "/usr/local/lib/python2.7/site-packages/distributed/client.py", line 1562, in gather
asynchronous=asynchronous)
File "/usr/local/lib/python2.7/site-packages/distributed/client.py", line 652, in sync
return sync(self.loop, func, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/distributed/utils.py", line 275, in sync
six.reraise(*error[0])
File "/usr/local/lib/python2.7/site-packages/distributed/utils.py", line 260, in f
result[0] = yield make_coro()
File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 1099, in run
value = future.result()
File "/usr/local/lib/python2.7/site-packages/tornado/concurrent.py", line 260, in result
raise_exc_info(self._exc_info)
File "/usr/local/lib/python2.7/site-packages/tornado/gen.py", line 1107, in run
yielded = self.gen.throw(*exc_info)
File "/usr/local/lib/python2.7/site-packages/distributed/client.py", line 1439, in _gather
traceback)
File "/usr/local/lib/python2.7/site-packages/dask/bytes/core.py", line 122, in read_block_from_file
with lazy_file as f:
File "/usr/local/lib/python2.7/site-packages/dask/bytes/core.py", line 166, in __enter__
f = SeekableFile(self.fs.open(self.path, mode=mode))
File "/usr/local/lib/python2.7/site-packages/dask/bytes/local.py", line 58, in open
return open(self._normalize_path(path), mode=mode)
IOError: [Errno 2] No such file or directory: 'file.csv'
I am not understanding what is wrong.Kindly help me with this .Thank you in advance .
You may wish to pass the absolute file path to read_csv. The reason is, that you are giving the work of opening and reading the file to a dask worker, and you might not have started that worked with the same working directory as your script/session.

Tensorflow NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory

I am trying to run this script from the YouTuber sentdex, but I get this error:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
The backend was *originally* set to 'TkAgg' by the following code:
File "Desktop/object.py", line 11, in <module>
from matplotlib import pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 71, in <module>
from matplotlib.backends import pylab_setup
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 16, in <module>
line for line in traceback.format_stack()
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
Traceback (most recent call last):
File "Desktop/object.py", line 86, in <module>
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/models/research/object_detection/utils/label_map_util.py", line 132, in load_labelmap
label_map_string = fid.read()
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 120, in read
self._preread_check()
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 80, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "/home/wdjpng/.local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 519, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory
OS: Ubuntu 18.04
Python: 2.7
Could you please help me ?
It would help immensly if you provided the file/function you called to produce the traceback. However, in absence of that and based on the below:
tensorflow.python.framework.errors_impl.NotFoundError: data/mscoco_label_map.pbtxt; No such file or directory
The *_label_map.pbtxt path is specified in two lines of the model.config file (exact line numbers depends on the model you chose). It appears one or both the training/test file paths are incorrect.

Matplotlib error, [Errno 2] No such file or directory: 'latex': 'latex'?

When I try running the very simple code snippet from www.matplotlib.org,
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)
import numpy as np
import matplotlib.pyplot as plt
# Example data
t = np.arange(0.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.plot(t, s)
plt.xlabel(r'\textbf{time} (s)')
plt.ylabel(r'\textit{voltage} (mV)',fontsize=16)
plt.title(r"\TeX\ is Number "
r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
fontsize=16, color='gray')
# Make room for the ridiculously large title.
plt.subplots_adjust(top=0.8)
plt.savefig('tex_demo')
plt.show()
This is highly unusual this code has worked for me before and I cannot figure out what the issue is. The error message that I receive is enormous and shown below. Does anybody know what the issue might be?
Thanks!!
Traceback (most recent call last):
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py",
line 332, in call
return printer(obj)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py",
line 237, in
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py",
line 121, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py",
line 2216, in print_figure
**kwargs)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py",
line 507, in print_png
FigureCanvasAgg.draw(self)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py",
line 430, in draw
self.figure.draw(self.renderer)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py",
line 1299, in draw
renderer, self, artists, self.suppressComposite)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/image.py",
line 138, in _draw_list_compositing_images
a.draw(renderer)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py",
line 2437, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/image.py",
line 138, in _draw_list_compositing_images
a.draw(renderer)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py",
line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py",
line 1135, in draw
renderer)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py",
line 1075, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/text.py",
line 933, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/text.py",
line 308, in _get_layout
ismath=False)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py",
line 226, in get_text_width_height_descent
s, fontsize, renderer=self)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py",
line 602, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File
"/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py",
line 393, in make_dvi
stderr=subprocess.STDOUT)
File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 336,
in check_output
**kwargs).stdout
File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 403,
in run
with Popen(*popenargs, **kwargs) as process:
File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 709,
in init
restore_signals, start_new_session)
File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 1344,
in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex':
'latex'
For linux:
sudo yum install latex
sudo yum install dvipng
For Window:
install texlive.
ref. https://matplotlib.org/tutorials/text/usetex.html?highlight=latex
Download miktex and add the path in environment variables for Windows.

pandas.read_csv gives FileNotFound error inside a loop

pandas.read_csv is working properly when used as a single statement. But it is giving FileNotFoundError when it is being used inside a loop even though the file exists.
for filename in os.listdir("./Datasets/pollution"):
print(filename) # To check which file is under processing
df = pd.read_csv(filename, sep=",").head(1)
These above lines are giving this following error.
pollutionData184866.csv <----- The name of the file is printed properly.
Traceback (most recent call last):
File "/home/parnab/PycharmProjects/FinalYearProject/locationExtractor.py", line 13, in <module>
df = pd.read_csv(i, sep=",").head(1)
File "/usr/lib/python3.6/site-packages/pandas/io/parsers.py", line 646, in parser_f
return _read(filepath_or_buffer, kwds)
File "/usr/lib/python3.6/site-packages/pandas/io/parsers.py", line 389, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "/usr/lib/python3.6/site-packages/pandas/io/parsers.py", line 730, in __init__
self._make_engine(self.engine)
File "/usr/lib/python3.6/site-packages/pandas/io/parsers.py", line 923, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "/usr/lib/python3.6/site-packages/pandas/io/parsers.py", line 1390, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "pandas/parser.pyx", line 373, in pandas.parser.TextReader.__cinit__ (pandas/parser.c:4184)
File "pandas/parser.pyx", line 667, in pandas.parser.TextReader._setup_parser_source (pandas/parser.c:8449)
FileNotFoundError: File b'pollutionData184866.csv' does not exist
But when I am doing
filename = 'pollutionData184866.csv'
df = pd.read_csv(filename, sep=',')
It is working fine.
What am I doing wrong?
os.listdir("./Datasets/pollution") returns a list of files without a path and according to the path "./Datasets/pollution" you are parsing CSV files NOT from the current directory ".", so changing it to glob.glob('./Datasets/pollution/*.csv') should work, because glob.glob() returns a list of satisfying files/directories including given path
Demo:
In [19]: os.listdir('d:/temp/.data/629509')
Out[19]:
['AAON_data.csv',
'AAON_data.png',
'AAPL_data.csv',
'AAPL_data.png',
'AAP_data.csv',
'AAP_data.png']
In [20]: glob.glob('d:/temp/.data/629509/*.csv')
Out[20]:
['d:/temp/.data/629509\\AAON_data.csv',
'd:/temp/.data/629509\\AAPL_data.csv',
'd:/temp/.data/629509\\AAP_data.csv']