anaconda-navigator not running after a abrupt shutdown - python

I was running anaconda-navigator in the past days. My system was abruptly shutdown one day. After that, when I run anaconda-navigator, it is showing the following error
dstlab2#dstlab2-Veriton-M200-H81:~$ anaconda-navigator
Traceback (most recent call last):
File "/home/dstlab2/anaconda3/bin/anaconda-navigator", line 11, in <module>
sys.exit(main())
File "/home/dstlab2/anaconda3/lib/python3.7/site-packages/anaconda_navigator/app/main.py", line 99, in main
from anaconda_navigator.utils.logs import clean_logs
File "/home/dstlab2/anaconda3/lib/python3.7/site-packages/anaconda_navigator/utils/logs.py", line 18, in <module>
from anaconda_navigator.config import (LOG_FILENAME, LOG_FOLDER,
File "/home/dstlab2/anaconda3/lib/python3.7/site-packages/anaconda_navigator/config/__init__.py", line 27, in <module>
from anaconda_navigator.config.main import CONF
File "/home/dstlab2/anaconda3/lib/python3.7/site-packages/anaconda_navigator/config/main.py", line 71, in <module>
raw_mode=True,
File "/home/dstlab2/anaconda3/lib/python3.7/site-packages/anaconda_navigator/config/user.py", line 221, in __init__
self.load_from_ini()
File "/home/dstlab2/anaconda3/lib/python3.7/site-packages/anaconda_navigator/config/user.py", line 279, in load_from_ini
self.read(self.filename(), encoding='utf-8')
File "/home/dstlab2/anaconda3/lib/python3.7/configparser.py", line 696, in read
self._read(fp, filename)
File "/home/dstlab2/anaconda3/lib/python3.7/configparser.py", line 1014, in _read
for lineno, line in enumerate(fp, start=1):
File "/home/dstlab2/anaconda3/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf2 in position 378: invalid continuation byte
can anyone help me how to set things right?

It looks as if a configuration file used by anaconda navigator has been corrupted. The file probably exists in the $HOME/.anaconda folder; it may have a .ini extension.
If you can identify the file, you could try replacing the byte that's causing the problem (make a backup copy of the file first):
>>> with open('config.ini', 'rb+') as f:
... data = f.read()
... data = data.replace(b'\xf2', b'')
... assert data
... f.seek(0)
... f.write(data)
...
0
171
Note that there may be more than one byte.
It's also possible that the file has been truncated or corrupted so much that it needs to be deleted or replaced entirely.

Related

AWS SAM, AWS Lambda, UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 66: invalid start byte

I followed the example of (Serverless Deployment of ML models on AWS Lambda) and had no problems with running the code locally and on AWS.
I tried to adjust the original example for Fastai model. However, after sam local start-api and running the testing code in the local Jupyter notebook, I get the error.
The change I made was:
loc_fastai = torch.load('test-fastai-project.pth')
instead of
knnclf = joblib.load('knnclf.joblib')
The error looks like:
Traceback (most recent call last):
File "/var/runtime/bootstrap.py", line 60, in <module>
main()
File "/var/runtime/bootstrap.py", line 55, in main
add_default_site_directories()
File "/var/runtime/bootstrap.py", line 42, in add_default_site_directories
site.addsitedir(os.environ["LAMBDA_TASK_ROOT"])
File "/var/lang/lib/python3.9/site.py", line 208, in addsitedir
addpackage(sitedir, name, known_paths)
File "/var/lang/lib/python3.9/site.py", line 164, in addpackage
for n, line in enumerate(f):
File "/var/lang/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 66: invalid start byte
27 Nov 2022 10:55:04,361 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 1 InvokeID=
Traceback (most recent call last):
File "/var/runtime/bootstrap.py", line 60, in <module>
main()
File "/var/runtime/bootstrap.py", line 55, in main
add_default_site_directories()
File "/var/runtime/bootstrap.py", line 42, in add_default_site_directories
site.addsitedir(os.environ["LAMBDA_TASK_ROOT"])
File "/var/lang/lib/python3.9/site.py", line 208, in addsitedir
addpackage(sitedir, name, known_paths)
File "/var/lang/lib/python3.9/site.py", line 164, in addpackage
for n, line in enumerate(f):
File "/var/lang/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 66: invalid start byte
END RequestId:
Obviously, the code does not reach lambda_predict.py. I tried to remove that code and return to the example 1, but without success. I get the error continuously. I tried removing the images, also without success. I noticed only removing the images, restarting the docker (Docker for Windows), and creating a new project. However, repeating the code for reading the fastai model gives the error again.
I also tried putting in the docker file:
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
After the error, I guess the state is cashed, but I don't know where to look.
How to solve this problem?

dvc.api.read() raises an "UnicodeDecodeError"

I am trying to acess a DICOM file [image saved in the Digital Imaging and Communications in Medicine (DICOM) format]:
import dvc.api
path = 'dir/image.dcm'
remote = 'remote_name'
repo = 'git_repo'
mode = 'r'
data = dvc.api.read(path = path, remote = remote, repo = repo, mode = mode)
When I run the previous code, and after the "downloading progress bar" is complete, I get the following error:
Traceback (most recent call last): File "draft.py", line 7, in <module> mode ='r') File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\api.py", line 91, in read return fd.read() File "C:\Users\lbrandao\anaconda3\envs\my_env\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 764: character maps to <undefined>
I tried to overcome this issue by using the encoding argument:
data = dvc.api.read(path = path, remote = remote, repo = repo, mode = mode, encoding='ANSI')
Since, when I open a DICOM file using for example Notepad++, this is the encoding specified. However, it raises the error:
Exception ignored in: <bound method Pool.__del__ of <dvc.fs.pool.Pool object at 0x0000021D1347A160>> Traceback (most recent call last): File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\fs\pool.py", line 42, in __del__ File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\fs\pool.py", line 46, in close File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\dvc\fs\ssh\connection.py", line 71, in close File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\paramiko\sftp_client.py", line 194, in close File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\paramiko\sftp_client.py", line 185, in _log File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\site-packages\paramiko\sftp.py", line 158, in _log File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\logging\__init__.py", line 1372, in log File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\logging\__init__.py", line 1441, in _log File "C:\Users\lbrandao\anaconda3\envs\my_env\lib\logging\__init__.py", line 1411, in makeRecord TypeError: 'NoneType' object is not callable
I also tried encoding = 'utf-8', but the "UnicodeDecodeError" continues to appear:
Traceback (most recent call last): File "draft.py", line 7, in <module> mode ='r', encoding='utf-8') File "C:\Users\lbrandao\anaconda3\envs\ccab_env_dev\lib\site-packages\dvc\api.py", line 91, in read return fd.read() File "C:\Users\lbrandao\anaconda3\envs\ccab_env_dev\lib\codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 140: invalid continuation byte
Can anyone please help? Thanks.
I am not familiar with dvc.api, but a lot of people who deal with DICOMs use either pydicom or simpleITK. I wrote a library which can get most of the the data using either (cleanX) and you can look at an example notebook here.

Spyder crashes at start: UnicodeDecodeError

During a Spyder session my Linux froze. After startup, I could not start Spyder; I got the following error instead:
(trusty)dreamer#localhost:~$ spyder
Traceback (most recent call last):
File "/home/dreamer/anaconda2/bin/spyder", line 2, in <module>
from spyderlib import start_app
File "/home/dreamer/anaconda2/lib/python2.7/site-packages/spyderlib/start_app.py", line 13, in <module>
from spyderlib.config import CONF
File "/home/dreamer/anaconda2/lib/python2.7/site-packages/spyderlib/config.py", line 736, in <module>
subfolder=SUBFOLDER, backup=True, raw_mode=True)
File "/home/dreamer/anaconda2/lib/python2.7/site-packages/spyderlib/userconfig.py", line 215, in __init__
self.load_from_ini()
File "/home/dreamer/anaconda2/lib/python2.7/site-packages/spyderlib/userconfig.py", line 260, in load_from_ini
self.readfp(configfile)
File "/home/dreamer/anaconda2/lib/python2.7/ConfigParser.py", line 324, in readfp
self._read(fp, filename)
File "/home/dreamer/anaconda2/lib/python2.7/ConfigParser.py", line 479, in _read
line = fp.readline()
File "/home/dreamer/anaconda2/lib/python2.7/codecs.py", line 690, in readline
return self.reader.readline(size)
File "/home/dreamer/anaconda2/lib/python2.7/codecs.py", line 545, in readline
data = self.read(readsize, firstline=True)
File "/home/dreamer/anaconda2/lib/python2.7/codecs.py", line 492, in read
newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xfe in position 2: invalid start byte
(trusty)dreamer#localhost:~$
I have found this solution, which sounds very much like my problem, but am curious if there are others, and whether anyone knows why this occurred.
My guess is that your spyder configuration file somehow got corrupted. This is the file spyder.ini, which resides in a directory like ~/.spyder2 (the exact name of the directory depends on the version you have installed). Maybe the encoding of the configuration file changed or a Unicode byte order mark was somehow introduced.
Possible solutions: use an editor to convert the file back to UTF-8; delete the configuration file; delete the whole directory containing the configuration file. The last two obviously delete any changes you made to the configuration.

spyder - python IDE uft8 encoding loading issue

I am unable to get spyder to load. I am running windows 7, 64 bit.
I have installed Anaconda-2.3.0 64 bit and have attempted to run the bundled spyder.
I have also tried the latest separate spyder build and encountered the exact same issue.
When running spyder via cmd I recieve the following error message:
"
Traceback (most recent call last):
File "C:\Anaconda\scripts\spyder", line 2, in <module>
from spyderlib import start_app
File "C:\Anaconda\lib\site-packages\spyderlib\start_app.py", line 13, in <modu
le>
from spyderlib.config import CONF
File "C:\Anaconda\lib\site-packages\spyderlib\config.py", line 718, in <module
>
subfolder=SUBFOLDER, backup=True, raw_mode=True)
File "C:\Anaconda\lib\site-packages\spyderlib\userconfig.py", line 215, in __i
nit__
self.load_from_ini()
File "C:\Anaconda\lib\site-packages\spyderlib\userconfig.py", line 260, in loa
d_from_ini
self.readfp(configfile)
File "C:\Anaconda\lib\ConfigParser.py", line 324, in readfp
self._read(fp, filename)
File "C:\Anaconda\lib\ConfigParser.py", line 479, in _read
line = fp.readline()
File "C:\Anaconda\lib\codecs.py", line 678, in readline
return self.reader.readline(size)
File "C:\Anaconda\lib\codecs.py", line 533, in readline
data = self.read(readsize, firstline=True)
File "C:\Anaconda\lib\codecs.py", line 480, in read
newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe8 in position 59: invalid
continuation byte
"
Is there some way to fix this?
Thanks
Never mind. Figured it out.
uninstall/reinstall anaconda.
delete Libraries\Documents.spyder2 folder
Run spyder. Wait a long time. spyder loads.
yay.

UnicodeDecodeError when reading dictionary words file with simple Python script

First time doing Python in a while, and I'm having trouble doing a simple scan of a file when I run the following script with Python 3.0.1,
with open("/usr/share/dict/words", 'r') as f:
for line in f:
pass
I get this exception:
Traceback (most recent call last):
File "/home/matt/install/test.py", line 2, in <module>
for line in f:
File "/home/matt/install/root/lib/python3.0/io.py", line 1744, in __next__
line = self.readline()
File "/home/matt/install/root/lib/python3.0/io.py", line 1817, in readline
while self._read_chunk():
File "/home/matt/install/root/lib/python3.0/io.py", line 1565, in _read_chunk
self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
File "/home/matt/install/root/lib/python3.0/io.py", line 1299, in decode
output = self.decoder.decode(input, final=final)
File "/home/matt/install/root/lib/python3.0/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1689-1692: invalid data
The line in the file it blows up on is "Argentinian", which doesn't seem to be unusual in any way.
Update: I added,
encoding="iso-8559-1"
to the open() call, and it fixed the problem.
How have you determined from "position 1689-1692" what line in the file it has blown up on? Those numbers would be offsets in the chunk that it's trying to decode. You would have had to determine what chunk it was -- how?
Try this at the interactive prompt:
buf = open('the_file', 'rb').read()
len(buf)
ubuf = buf.decode('utf8')
# splat ... but it will give you the byte offset into the file
buf[offset-50:60] # should show you where/what the problem is
# By the way, from the error message, looks like a bad
# FOUR-byte UTF-8 character ... interesting
Can you check to make sure it is valid UTF-8? A way to do that is given at this SO question:
iconv -f UTF-8 /usr/share/dict/words -o /dev/null
There are other ways to do the same thing.

Categories