I want to use Facebook's prophet,however when I try to create a model:
model = prt.Prophet(stan_backend='CMDSTANPY')
It occurs mistake like this:
Traceback (most recent call last):
File "C:\Users\UserName\IdeaProjects\station-simulate\stcd-predict.py", line 24, in <module>
model = prt.Prophet(stan_backend='CMDSTANPY')
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 142, in __init__
self._load_stan_backend(stan_backend)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 153, in _load_stan_backend
self.stan_backend = StanBackendEnum.get_backend_class(stan_backend)()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\models.py", line 67, in __init__
super().__init__()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\models.py", line 23, in __init__
self.model = self.load_model()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\models.py", line 79, in load_model
return cmdstanpy.CmdStanModel(exe_file=model_file)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\cmdstanpy\model.py", line 192, in __init__
do_command(['where.exe', 'tbb.dll'], fd_out=None)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\cmdstanpy\utils\command.py", line 53, in do_command
line = proc.stdout.readline()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
If I don't use stan_backend='CMDSTANPY':
Traceback (most recent call last):
File "C:\Users\k6789\IdeaProjects\station-simulate\stcd-predict.py", line 24, in <module>
model = prt.Prophet()
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 141, in __init__
self._load_stan_backend(stan_backend)
File "C:\ProgramData\Anaconda3\envs\my1stconda\lib\site-packages\prophet\forecaster.py", line 154, in _load_stan_backend
logger.debug("Loaded stan backend: %s", self.stan_backend.get_type())
AttributeError: 'Prophet' object has no attribute 'stan_backend'
I re-setup prophet with micromamba and it has no effect.
How to solve this?
Now I changed another computer and created a new conda environment,solved this.
I am running the following code in spyder
df_test=pd.read_csv(request.files.get("file"))
print(df_test.head())
prediction=classifier.predict(df_test)
and getting the error
File "/opt/anaconda3/lib/python3.9/site-packages/pandas/io/parsers/c_parser_wrapper.py", line 69, in __init__
self._reader = parsers.TextReader(self.handles.handle, **kwds)
File "pandas/_libs/parsers.pyx", line 542, in pandas._libs.parsers.TextReader.__cinit__
File "pandas/_libs/parsers.pyx", line 642, in pandas._libs.parsers.TextReader._get_header
File "pandas/_libs/parsers.pyx", line 843, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas/_libs/parsers.pyx", line 1917, in pandas._libs.parsers.raise_parser_error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd8 in position 10: invalid continuation byte
Have tried other solutions also but nothing has worked.
Have you tried passing the argument encoding="latin-1'" into your read_csv?
I am trying to execute a read file command from command line inside a container in k8s for a django app but i get this error. I am able to execute the same command locally but not inside k8s. My complete error stack is as follows:
raceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/code/setup/management/commands/load.py", line 40, in handle
raw = file.read()
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 223: ordinal not in range(128)
here is the code:
with codecs.open(filename, 'r', encoding='utf-8') as file:
raw = file.read()
data = json.loads(raw)
Traceback (most recent call last):
File "/Applications/Sublime
Text.app/Contents/MacOS/sublime_plugin.py", line 818, in run_
return self.run(edit)
File "open_in_browser in /Applications/Sublime
Text.app/Contents/MacOS/Packages/Default.sublime-package", line 9, in run
File "./python3.3/webbrowser.py", line 70, in open_new_tab
File "./python3.3/webbrowser.py", line 62, in open
File "./python3.3/webbrowser.py", line 635, in open
UnicodeEncodeError: 'ascii' codec can't encode characters in position
56-57: ordinal not in range(128)
How can i fix this? I use the plugin SidebarEnhancements to open my html,but I meet this problem.
For a project I'm supposed to enhance some XML and store it in a file. The problem I encountered is that I keep getting the following error:
Traceback (most recent call last):
File "C:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap
self.run()
File "C:\Python27\lib\multiprocessing\process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Bart\Dropbox\Studie\2013-2014\BSc-KI\cite_parser\parser.py", line 193, in parse_references
outputXML = ET.tostring(root, encoding='utf8', method='xml')
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1126, in tostring
ElementTree(element).write(file, encoding, method=method)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 820, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 939, in _serialize_xml
_serialize_xml(write, e, encoding, qnames, None)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 939, in _serialize_xml
_serialize_xml(write, e, encoding, qnames, None)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 939, in _serialize_xml
_serialize_xml(write, e, encoding, qnames, None)
ECLI:NL:RVS:2012:BY1564
File "C:\Python27\lib\xml\etree\ElementTree.py", line 937, in _serialize_xml
write(_escape_cdata(text, encoding))
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1073, in _escape_cdata
return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 80: ordinal not in range(128)
That error was generated by:
outputXML = ET.tostring(root, encoding='utf8', method='xml')
When looking for a solution to this problem i found several suggestions saying I should add .decode('utf-8') to the function but that results in an Encoding error (first it was decoding) from the write function so that doesn't work...
The encoding error:
Traceback (most recent call last):
File "C:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap
self.run()
File "C:\Python27\lib\multiprocessing\process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Bart\Dropbox\Studie\2013-2014\BSc-KI\cite_parser\parser.py", line 197, in parse_references
myfile.write(outputXML)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xeb' in position 13559: ordinal not in range(128)
It is generated by the following code:
outputXML = ET.tostring(root, encoding='utf8', method='xml').decode('utf-8')
Source (or at least the relevant parts):
# URL encodes the parameters
encoded_parameters = urllib.urlencode({'id':ecli})
# Opens XML file
feed = urllib2.urlopen("http://data.rechtspraak.nl/uitspraken/content?"+encoded_parameters, timeout = 3)
# Parses the XML
ecliFile = ET.parse(feed)
# Fetches root element of current tree
root = ecliFile.getroot()
# Write the XML to a file without any extra indents or newlines
outputXML = ET.tostring(root, encoding='utf8', method='xml')
# Write the XML to the file
with open(file, "w") as myfile:
myfile.write(outputXML)
And last but not least an URL to an XML sample: http://data.rechtspraak.nl/uitspraken/content?id=ECLI:NL:RVS:2012:BY1542
The exception is caused by a byte string value.
text in the traceback is supposed to be a unicode value, but if it is a plain byte string, Python will implicitly first decode it (with the ASCII codec) to Unicode just so you can then encode it again.
It is that decoding that fails.
Because you didn't actually show us what you insert into the XML tree, it is hard to tell you what to fix, other than to make sure you always use Unicode values when inserting text.
Demo:
>>> root.attrib['oops'] = u'Data with non-ASCII codepoints \u2014 (em dash)'.encode('utf8')
>>> ET.tostring(root, encoding='utf8', method='xml')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/mj/Development/Library/buildout.python/parts/opt/lib/python2.7/xml/etree/ElementTree.py", line 1126, in tostring
ElementTree(element).write(file, encoding, method=method)
File "/Users/mj/Development/Library/buildout.python/parts/opt/lib/python2.7/xml/etree/ElementTree.py", line 820, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "/Users/mj/Development/Library/buildout.python/parts/opt/lib/python2.7/xml/etree/ElementTree.py", line 932, in _serialize_xml
v = _escape_attrib(v, encoding)
File "/Users/mj/Development/Library/buildout.python/parts/opt/lib/python2.7/xml/etree/ElementTree.py", line 1090, in _escape_attrib
return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 31: ordinal not in range(128)
>>> root.attrib['oops'] = u'Data with non-ASCII codepoints \u2014 (em dash)'
>>> ET.tostring(root, encoding='utf8', method='xml')
'<?xml version=\'1.0\' encoding=\'utf8\'?> ...'
Setting a bytestring attribute, containing bytes outside the ASCII range, triggers the excetpion; using a unicode value instead ensured the result could be produced.