Python: error problems to import module matplotlib - python

This afternoon after installing progressbar I have this problem importing matplolib:
>>> import matplotlib
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 772, in <module>
rcParams = rc_params()
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 690, in rc_params
fname = matplotlib_fname()
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 602, in matplotlib_fname
fname = os.path.join(get_configdir(), 'matplotlibrc')
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 253, in wrapper
ret = func(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 475, in _get_configdir
raise RuntimeError("'%s' is not a writable dir; you must set %s/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored "% (h, h))
RuntimeError: 'C:\Users\ALEM' is not a writable dir; you must set C:\Users\ALEM/.matplotlib to be a writable dir. You can also set environment variable MPLCONFIGDIR to any writable directory where you want matplotlib data stored
I had tried to reinstall matplolib and python 27 several times on my windows 7 64 bit, but I have always the same error.
The Error message says:
please run the chkdsk utility
But I don't understand where is this utility and how I can run it.

Related

Using matplotlib to create a histogram on Windows Subsystem for Linux Ubuntu

I am trying to create a simple histogram for a csv file named "count_backers.csv". The code that I have so far is as follows:
import matplotlib.pyplot as plt
# import numpy as np
import plotly.plotly as py
import csv
def make_hist(csv_filepath):
data = open(csv_filepath)
reader = csv.reader(data)
column = []
for row in data:
column.append(row)
plt.hist(column)
plt.title("Number of Backers")
plt.xlabel("Frequency")
plt.ylabel("Value")
plt.show()
# fig = plt.gcf()
# plot_url = py.plot_mpl(fig, filename='backers_histogram')
backer_data = r"C:/Users/user/Documents/user/Programming/count_backers.csv"
make_hist(backer_data)
I began learning python using Learn Python the Hard Way, and I am used to executing python files from PowerShell. However, I was struggling to install and build matplotlib on Windows and for the sake of time I decided to install it on Windows Subsystem for Linux Ubuntu. After I was able to get that working I am now getting the following error:
Traceback (most recent call last):
File "histogram.py", line 22, in <module>
make_hist(backer_data)
File "histogram.py", line 7, in make_hist
data = open(csv_filepath)
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/user/Documents/user/Programming/count_backers.csv'
I have tried several different versions of the filepath including:
backer_data = r"C:\Users\user\Documents\user\Programming\count_backers.csv"
backer_data = "mnt/c/Users/user/Documents/user/Programming/count_backers.csv"
backer_data = r"mnt\c\Users\user\Documents\user\Programming\count_backers.csv"
These produce the following errors respectively:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\Documents\\user\\Programming\\count_backers.csv'
FileNotFoundError: [Errno 2] No such file or directory: 'mnt/c/Users/user/Documents/user/Programming/count_backers.csv'
FileNotFoundError: [Errno 2] No such file or directory: 'mnt\\c\\Users\\user\\Documents\\user\\Programming\\count_backers.csv'
When I use ls on the specified directory though it does show the file being there:
smidem#JealousHippo:/mnt/c/Users/user/Documents/user/Programming$ ls
column_avg.py count_backers.csv histogram.py pledged.csv
I'm pretty confused as to why it is unable to locate this file and any help would be greatly appreciated.
With l0b0's help I changed backer_data to backer_data = "/mnt/c/Users/user/Documents/user/Programming/count_backers.csv" but I am now receiving this in response:
Traceback (most recent call last):
File "histogram.py", line 22, in <module>
make_hist(backer_data)
File "histogram.py", line 12, in make_hist
plt.hist(column)
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 2947, in hist
ax = gca()
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 928, in gca
return gcf().gca(**kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 578, in gcf
return figure()
File "/usr/lib/python3/dist-packages/matplotlib/pyplot.py", line 527, in figure
**kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/lib/python3.5/tkinter/__init__.py", line 1871, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
"mnt/c/Users/user/Documents/user/Programming/count_backers.csv" is a relative path starting at the current working directory, which most likely is not the filesystem root. Try starting the path with a slash.

Pychecker index error on first run

I've just installed pychecker on windows 7 Pro using "python setup.py install". When I run it on my script using the command:
c:\Python26\Scripts\pychecker -#100 finaltest17.py
I get the following error/traceback:
C:\Users\....\ToBeReleased>C:\Python26\python.exe C:\Python26\Lib\site-packages\pychecker\checker.py -#100 finaltest17.py
Processing module finaltest17 (finaltest17.py)...
Caught exception importing module finaltest17:
File "C:\Python26\Lib\site-packages\pychecker\pcmodules.py", line 533, in setupMainCode()
self.moduleName, self.moduleDir)
File "C:\Python26\Lib\site-packages\pychecker\pychecker\utils.py", line 184, in findModule()
handle, filename, smt = _q_find_module(p, path)
File "C:\Python26\Lib\site-packages\pychecker\pychecker\utils.py", line 162, in _q_find_module()
if not cfg().quixote:
File "C:\Python26\Lib\site-packages\pychecker\pychecker\utils.py", line 39, in cfg()
return _cfg[-1]
IndexError: list index out of range
Traceback (most recent call last):
File "C:\Python26\Lib\site-packages\pychecker\checker.py", line 364, in <module>
sys.exit(main(sys.argv))
File "C:\Python26\Lib\site-packages\pychecker\checker.py", line 337, in main
importWarnings = processFiles(files, _cfg, _print_processing)
File "C:\Python26\Lib\site-packages\pychecker\checker.py", line 270, in processFiles
loaded = pcmodule.load()
File "C:\Python26\Lib\site-packages\pychecker\pcmodules.py", line 477, in load
return utils.cfg().ignoreImportErrors
File "C:\Python26\Lib\site-packages\pychecker\pychecker\utils.py", line 39, in cfg
return _cfg[-1]
IndexError: list index out of range
If anyone could point me in the right direction that would be great.
Thanks
Stewart
Problem resolved.
I found the following support request on SourceForge which refers to a need to use short format (8.3) path and filenames in pychecker.bat and not long format as is allowed in newer versions of Windows.
https://sourceforge.net/p/pychecker/support-requests/7/#96cb

Setting up caffe on Ubuntu 14.04 but facing errors when running classify.py

I'm installing Caffe on an Ubuntu 14.04 virtual server with CUDA installed (without driver) using https://github.com/BVLC/caffe/wiki/Ubuntu-14.04-VirtualBox-VM as inspiration. I've installed all the necessary dependencies and have followed all the instructions step by step but get the error below when I try to test the installation.
In regards to the step:
" Modify python/classify.py to add the --print_results option"
I had amended the code via in classify.py to be identical to the official caffe distribution. Not sure if that is the step that is causing the problem but thought I'd add that extra piece of information just in case.
The error i get is as below:
vagrant#vagrant-ubuntu-trusty-64:~/caffe$ sudo python python/classify.py --print_results examples/images/cat.jpg foo
libdc1394 error: Failed to initialize libdc1394
Traceback (most recent call last):
File "python/classify.py", line 14, in <module>
import caffe
File "/home/vagrant/caffe/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
File "/home/vagrant/caffe/python/caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "/home/vagrant/caffe/python/caffe/io.py", line 2, in <module>
import skimage.io
File "/usr/local/lib/python2.7/dist-packages/skimage/io/__init__.py", line 15, in <module>
reset_plugins()
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 89, in reset_plugins
_load_preferred_plugins()
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 69, in _load_preferred_plugins
_set_plugin(p_type, preferred_plugins['all'])
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 81, in _set_plugin
use_plugin(plugin, kind=plugin_type)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 251, in use_plugin
_load(name)
File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 295, in _load
fromlist=[modname])
File "/usr/local/lib/python2.7/dist-packages/skimage/io/_plugins/matplotlib_plugin.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1131, in <module>
rcParams = rc_params()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 975, in rc_params
return rc_params_from_file(fname, fail_on_error)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1100, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1018, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1000, in _open_file_or_url
encoding = locale.getdefaultlocale()[1]
File "/usr/lib/python2.7/locale.py", line 543, in getdefaultlocale
return _parse_localename(localename)
File "/usr/lib/python2.7/locale.py", line 475, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
Any input would be greatly appreciated. Thank you.
Check your current shell environment, these variables: LC_ALL, LC_CTYPE, LANG, LANGUAGE:
set | grep -a '^LC_ALL=.'; set | grep -a '^LC_CTYPE=.';
set | grep -a '^LANG=.'; set | grep -a '^LANGUAGE=.'
Likely the first printed line will contain one of these variables equal to 'UTF-8'. This is wrong.
A proper locale should have language and optional country and encoding specification, like 'en' or 'en_US' or 'ru_RU.UTF-8'. There's a special locale 'C' used as fallback.
So you may redefine your locale permanently in /etc/default/locale (don't forget to reload your settings, the easiest way is to logoff/logon), or simply override it for a particular command:
> LC_ALL=C python python/classify.py --print_results examples/images/cat.jpg foo
Regarding libdc1394: if you don't need interaction with FireWire check ctypes error: libdc1394 error: Failed to initialize libdc1394

CanĀ“t save matplotlib figure to .eps in Windows while using text.usetex : True

When I run the following code: http://dpaste.com/0210P09 everything works fine on my Linux distro.
However, in Windows7 (64bit) I cannot successfully save it in eps or svg.
This is the error that I get:
Traceback (most recent call last):
File "<ipython-input-1-b8da411d11b0>", line 1, in <module>
runfile('C:/Users/12151056/Documents/Python Scripts/MyPython/1Tplot_2.py', wdir='C:/Users/12151056/Documents/Python Scripts/MyPython')
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/12151056/Documents/Python Scripts/MyPython/1Tplot_2.py", line 67, in <module>
plt.savefig('excel-6.eps')
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 577, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1476, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2211, in print_figure
**kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1009, in print_eps
return self._print_ps(outfile, 'eps', *args, **kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1033, in _print_ps
**kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1398, in _print_figure_tex
rotated=psfrag_rotated)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1556, in gs_distill
your image.\nHere is the full report generated by ghostscript:\n\n' + fh.read())
TypeError: Can't convert 'bytes' object to str implicitly
If i use text.usetex : False I have no problem at all.
I have livetex full and Ghostscript installed.
Any suggestions to try and solve it?
There are two problems here. The first and minor one is that in
C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-package\matplotlib\backends\backend_ps.py", line 1556
you should change
fh.read()
to
fh.read().decode()
This is a Python 2/3 bug, that occurs while handling the fact that something with Ghostscript went wrong.
The main problem is that matplotlib cannot find Ghostscript because it is not in the path environmental variable. You can check that by opening a command prompt and trying the command gswin32c or gs. If these commands are not found you have to add the path of these Ghostscript executables to the path environmental variable. In my case it was:
C:\Program Files (x86)\gs\gs8.54\bin
but it depends on your installation path.

help('modules') crashing? Not sure how to fix

I was trying to install a module for opencv and added an opencv.pth file to the folder beyond my sites.py file. I have since deleted it and no change.
When I try to run help('modules'), I get the following error:
Please wait a moment while I gather a
list of all available modules...
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/words/im/init.py:8:
UserWarning: twisted.im will be
undergoing a rewrite at some point in
the future.
warnings.warn("twisted.im will be
undergoing a rewrite at some point in
the future.")
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py:110:
DeprecationWarning: The wxPython
compatibility package is no longer
automatically generated or actively
maintained. Please switch to the wx
package as soon as possible.
import(name) Traceback (most recent call last): File "",
line 1, in File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site.py",
line 348, in call
return pydoc.help(*args, **kwds) File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py",
line 1644, in call
self.help(request) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py",
line 1681, in help
elif request == 'modules': self.listmodules() File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py",
line 1802, in listmodules
ModuleScanner().run(callback) File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py",
line 1853, in run
for importer, modname, ispkg in pkgutil.walk_packages(): File
"/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py",
line 110, in walk_packages
import(name) File "/BinaryCache/wxWidgets/wxWidgets-11~262/Root/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wxaddons/init.py",
line 180, in import_hook File
"/Library/Python/2.5/site-packages/ctypes_opencv/init.py",
line 19, in
from ctypes_opencv.cv import * File
"/BinaryCache/wxWidgets/wxWidgets-11~262/Root/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wxaddons/init.py",
line 180, in import_hook File
"/Library/Python/2.5/site-packages/ctypes_opencv/cv.py",
line 2567, in ('desc', CvMat_r, 1), # CvMat* desc File
"/Library/Python/2.5/site-packages/ctypes_opencv/cxcore.py",
line 114, in cfunc
return CFUNCTYPE(result, *atypes)((name, dll), tuple(aflags)) AttributeError: dlsym(0x2674d10, cvCreateFeatureTree): symbol not found
What gives?!
This happens because help('modules') imports all modules, which can result in a lot of unsentineled code being executed. There's nothing you can do short of reporting bugs in every single package that causes this (opencv in this case) and wait for them to fix it.

Categories

Resources