I am testing some models between other things in my python 2.7.6 interpreter cia bpython package installed with pip.
In addition I am using a virtualenv created previously.
When I try type a doblequoes ("") or even slash ("/") character, I get the following message:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8e in position 1: ordinal not in range(128)
>>> coll=sess.collections.create("")
Traceback (most recent call last):
File "/home/bgarcial/.virtualenvs/iRODS/bin/bpython", line 11, in <module>
sys.exit(main())
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsies.py", line 79, in main
interactive=(not exec_args))
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsies.py", line 177, in mainloop
process_event(e)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsies.py", line 135, in process_event
repl.process_event(e)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsiesfrontend/repl.py", line 488, in process_event
return self.process_key_event(e)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsiesfrontend/repl.py", line 629, in process_key_event
self.add_normal_character(e)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsiesfrontend/repl.py", line 848, in add_normal_character
self.cursor_offset += 1
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsiesfrontend/repl.py", line 1345, in _set_cursor_offset
self.update_completion()
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/curtsiesfrontend/repl.py", line 878, in update_completion
self.list_win_visible = BpythonRepl.complete(self, tab)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/repl.py", line 599, in complete
history=self.history)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/autocomplete.py", line 466, in get_completer_bpython
return get_completer(BPYTHON_COMPLETER, cursor_offset, line, **kwargs)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/autocomplete.py", line 446, in get_completer
cursor_offset, line, **kwargs)
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/autocomplete.py", line 174, in matches
for filename in self.safe_glob(os.path.expanduser(text)):
File "/home/bgarcial/.virtualenvs/iRODS/local/lib/python2.7/site-packages/bpython/autocomplete.py", line 161, in safe_glob
return glob.glob(pathname + '*')
File "/usr/lib/python2.7/glob.py", line 27, in glob
return list(iglob(pathname))
File "/usr/lib/python2.7/glob.py", line 60, in iglob
yield os.path.join(dirname, name)
File "/home/bgarcial/.virtualenvs/iRODS/lib/python2.7/posixpath.py", line 78, in join
path += b
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8e in position 1: ordinal not in range(128)
(iRODS)➜ ~
In my python interpreter I can see the UTF-8 encoding
(iRODS)➜ ~ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.stdout.encoding
UTF-8
>>>
But, when I use bpython or IPython (installed with pip) , is here when I get the error
(iRODS)➜ ~ bpython
bpython version 0.14.1 on top of Python 2.7.6 /home/bgarcial/.virtualenvs/iRODS/bin/python
>>> import sys
>>> print sys.stdout.encoding
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'FakeOutput' object has no attribute 'encoding'
>>>
In IPython (and IPython 2) works
(iRODS)➜ ~ ipython
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
Type "copyright", "credits" or "license" for more information.
IPython 2.4.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import sys
In [2]: print sys.stdout.encoding
UTF-8
In [3]:
But, the error of encoding denoted previously appear with python, bpython and IPython
I have a problem with some of my interpreter or unless with aome of these utilities associated to it?
As additional information, I am working in my interpreter an API that I installed with pip.
Is possible that there is some problem with these API in relation with Unicode support?
The API is named python-irodsclient (https://github.com/irods/python-irodsclient) and when I ask to developers that create it, they entered an issue in relation with my problem (https://github.com/irods/python-irodsclient/issues/22)
What situation may be happening?
Of anyway I did want share this information here.
Thanks
Related
I got this error when running python from command line on Windows 10:
C:\Users\windows> python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site.py", line 410, in register_readline
readline.read_history_file(history)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "C:\ProgramData\Anaconda3\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
for line in open(filename, 'r'):
File "C:\ProgramData\Anaconda3\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 991: character maps to <undefined>
I have not changed anything about my python environment, I was just running some scripts that I've been working on for the last week. I honestly have no idea where this could be coming from; it seems to be an issue when python reads in its history. Updating python and conda did nothing. I found a very similar issue on a Chinese site here but the solution is unhelpful.
At the moment, I cannot find any issues when continuing to run python or my scripts, but I don't want this to come back and bite me. Any help is appreciated!
As user metatoaster commented, the python history file contains bytes that cannot be decoded by your system's default encoding and may be deleted. If the file contains commands that you want to keep or review you can take a backup first and try reviewing its contents in a text editor.
You have a history file that contain characters that cannot be decoded. Remove the history file (POSIX: ~/.python_history, on Windows it might be %userprofile%/.python_history) and see if that problem goes away.
in 'history.py' file, try to change "for line in open(filename, 'r'):" to "for line in open(filename, 'r', encoding='utf-8'):"
I am using Paraview 4.0.1 under Ubuntu 14.04 LTS.
But I guess the answer to this question does not necessarily requires knowledge specific to Paraview python.
When I load a python prompt at the command line everything "works well":
$ pvpython
Python 2.7.6 (default, Oct 26 2016, 20:33:43)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from paraview.simple import *
paraview version 4.0.1
>>>
But when I load the python shell within the GUI, from paraview.simple import * fails, either when automatically (at startup) or explicitly imported:
Python 2.7.6 (default, Oct 26 2016, 20:33:43)
[GCC 4.8.4] on linux2
from paraview.simple import *
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/paraview/simple.py", line 41, in <module>
import servermanager
File "/usr/lib/python2.7/dist-packages/paraview/servermanager.py", line 3157, in <module>
__initialize()
File "/usr/lib/python2.7/dist-packages/paraview/servermanager.py", line 3148, in __initialize
c = Connection(iter.GetCurrentSessionId(), iter.GetCurrentSession())
File "/usr/lib/python2.7/dist-packages/paraview/servermanager.py", line 1935, in __init__
_createModules(self.Modules)
File "/usr/lib/python2.7/dist-packages/paraview/servermanager.py", line 2567, in _createModules
m.filters = createModule('filters')
File "/usr/lib/python2.7/dist-packages/paraview/servermanager.py", line 2629, in createModule
if (prop.GetInformationOnly() and propName != "TimestepValues" ) \
AttributeError: 'NoneType' object has no attribute 'GetInformationOnly'
>>> from paraview.simple import *
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/paraview/servermanager.py", line 2190, in find_module
if vtkPVPythonModule.HasModule(fullname):
AttributeError: 'NoneType' object has no attribute 'HasModule'
>>>
How can I trace the different sequence of steps taken by each mode of loading a python shell, so as to identify the source of error?
In addition to this manifestation, I found two other differences:
In the command prompt, from paraview.simple import * is not executed automatically, while in the GUI it is. Where is this set?
In the command prompt, having set PYTHONSTARTUP=${HOME}/.pythonrc, which sets import readline, rlcompleter (actually, within a try-except construct), allows for tab completion.
In the GUI, .pythonrc is not read. Why is this? How can I tell the filename which would be read upon startup if it exists?
I have found one option which gives some information, I do not know if it is the only/best one.
Setting
$ export PYTHONVERBOSE=2
(or a different integer for verbosity level [1]) gives a lot of info.
Still, I couldn't find the source of error...
I am working on a project which utilizes the wbdata package for python, which is a wrapper for the world bank api. It was working fine until I made what I have guessed to be to large of a request of data, which I had to cancel, and now the package won't even load when I use the import wbdata function. Here's what I get
Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun 11 2014, 10:40:02) [MSC
v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 2.1.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
In [1]: import wbdata as wb
Traceback (most recent call last):
File "<ipython-input-1-ae1872a5f07c>", line 1, in <module>
import wbdata as wb
File "C:\Users\Josh New\Anaconda\lib\site-packages\wbdata\__init__.py", line 23, in <module>
from .api import (get_country, get_data, get_dataframe, get_panel,
File "C:\Users\Josh New\Anaconda\lib\site-packages\wbdata\api.py", line 31, in <module>
from . import fetcher
File "C:\Users\Josh New\Anaconda\lib\site-packages\wbdata\fetcher.py", line 104, in <module>
if not len(CACHE.cache)== 0:
File "C:\Users\Josh New\Anaconda\lib\site-packages\wbdata\fetcher.py", line 82, in cache
cache = pickle.load(cachefile)
EOFError
In [2]:
Could someone please help me out with getting this package working again?
Thanks
Josh
EDIT- Ok after running the %debug cachefile.name I get the following;
%debug cachefile.name
NOTE: Enter 'c' at the ipdb> prompt to continue execution.
> c:\users\josh new\anaconda\lib\encodings\cp1252.py(15)decode()
14 def decode(self,input,errors='strict'):
---> 15 return codecs.charmap_decode(input,errors,decoding_table)
16
ipdb> c
Traceback (most recent call last):
File "C:\Users\Josh New\Anaconda\lib\site-packages\IPython\core\magics\execution.py", line 817, in _run_with_debugger
deb.run(code, code_ns)
File "C:\Users\Josh New\Anaconda\lib\bdb.py", line 400, in run
exec cmd in globals, locals
File "<string>", line 1, in <module>
NameError: name 'cachefile' is not defined
Use ipython's magic %debug and check what cachefile's file name is. If it's a regular file, name should be accessible as cachefile.name.
Then nuke that file.
I think I have fixed it by going the wbdata folder in Appdata\Local\wbdata and deleting the cache file that was in it. seems to work now.
I am running Enthought Canopy 64-bit Version 1.1.1.1452 on OSX 10.9. I am trying to get the Enthought Canopy package "chaco 4.3.0-3" up and running for 2D interactive plotting. However, even the simplest chaco demos raise an error. From the stack trace, it looks as though It looks like the problem is related to loading fonts.
I am following the quick-start instructions here:
http://docs.enthought.com/chaco/quickstart.html
However, when I try to run the simple_line.py demo, I get the following error:
Last login: Mon Dec 2 15:20:35 on ttys000
dnab434def:demo mike$ pwd
/Users/mike/Library/Enthought/Canopy_64bit/User/Examples/chaco-4.2.0/demo
dnab434def:demo mike$ python
Enthought Canopy Python 2.7.3 | 64-bit | (default, Aug 8 2013, 05:37:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
dnab434def:demo mike$ python simple_line.py
Traceback (most recent call last):
File "simple_line.py", line 24, in <module>
from enable.api import Component, ComponentEditor
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/enable/api.py", line 8, in <module>
from base import IDroppedOnHandler, TOP, VCENTER, BOTTOM, LEFT, HCENTER, RIGHT, \
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/enable/base.py", line 31, in <module>
from kiva.constants import DEFAULT, DECORATIVE, ROMAN, SCRIPT, SWISS,\
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/__init__.py", line 19, in <module>
from fonttools import Font
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/__init__.py", line 1, in <module>
from font import Font, str_to_font
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/font.py", line 9, in <module>
from font_manager import FontProperties, fontManager
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/font_manager.py", line 1400, in <module>
_rebuild()
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/font_manager.py", line 1350, in _rebuild
fontManager = FontManager()
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/font_manager.py", line 1053, in __init__
self.ttffiles = findSystemFonts(paths) + findSystemFonts()
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/font_manager.py", line 422, in findSystemFonts
for f in OSXInstalledFonts(fontext=fontext):
File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/kiva/fonttools/font_manager.py", line 346, in OSXInstalledFonts
files.extend(glob.glob(os.path.join(path, '*.'+ext)))
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/glob.py", line 16, in glob
return list(iglob(pathname))
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/glob.py", line 41, in iglob
for dirname in dirs:
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/glob.py", line 42, in iglob
for name in glob_in_dir(dirname, basename):
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/glob.py", line 61, in glob1
return fnmatch.filter(names, pattern)
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/fnmatch.py", line 54, in filter
_cache[pat] = re.compile(res)
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/re.py", line 190, in compile
return _compile(pattern, flags)
File "/Applications/Canopy.app/appdata/canopy-1.1.0.1371.macosx-x86_64/Canopy.app/Contents/lib/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: bad character range
How can I work around this?
Apparently Chaco didn't like the custom fonts I had installed. Here is the workaround that worked for me.
I moved all my fonts out of the ~/Library/Fonts folder, then I ran "from chaco.shell import *" in an IPython notebook. Now I can use Chaco as per usual.
There must be some kind of weird caching happening, because I moved all my custom fonts back into the ~/Library/Fonts folder and Chaco still works.
Anyway, hopefully this will help someone if they get the same error message.
My Python interpreter is giving me an ugly error when I try to pull up a list of all the accessible modules (see below). I've googled "wx._core.PyNoAppError: The wx.App object must be created first!" and I haven't found a good explanation of how to fix it in this context. Can anyone help me out?
Python 2.5.4 (r254:67916, Aug 1 2011, 15:52:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> help('modules')
Please wait a moment while I gather a list of all available modules...
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pkgutil.py:110: DeprecationWarning: twisted.flow is unmaintained.
__import__(name)
/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.")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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 1645, in __call__
self.help(request)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1682, in help
elif request == 'modules': self.listmodules()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1803, in listmodules
ModuleScanner().run(callback)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/pydoc.py", line 1854, 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 "/var/tmp/wxWidgets/wxWidgets-13~231/2.5/DSTROOT/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wxaddons/__init__.py", line 29, in <module>
File "/var/tmp/wxWidgets/wxWidgets-13~231/2.5/DSTROOT/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-unicode/wx/_misc.py", line 3298, in __init__
wx._core.PyNoAppError: The wx.App object must be created first!
if you call help('modules') then, as defined in your site.py, pydoc.help() is called.
This results in a call to Helper.listmodules() which then calls the ModuleScanner() which is 'An interruptible scanner that searches module synopses' as per its docstring.
Unfortunately not all modules/packages are capable of being scanned, as that includes importing the module. You are however lucky that you just get an error. On my system (Linux, Python 2.7.3) this gives a segmentation fault