A strange scenario in anaconda -- Error while an attempt to launch Spyder - anaconda

enter image description here
I met this error while an attempt to launch Spyder.
Why?
Any replies to solution of this error will be grateful.
Error message.
Traceback (most recent call last):
File "C:\Users\user\anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\Users\user\anaconda3\lib\site-packages\spyder\app\start.py", line 128, in main
from spyder.config.manager import CONF
File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\manager.py", line 22, in
from spyder.config.main import CONF_VERSION, DEFAULTS, NAME_MAP
File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\main.py", line 19, in
from spyder.config.fonts import MEDIUM, SANS_SERIF
File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\fonts.py", line 14, in
from spyder.config.utils import is_ubuntu
File "C:\Users\user\anaconda3\lib\site-packages\spyder\config\utils.py", line 17, in
from spyder_kernels.utils import iofuncs
File "C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\utils\iofuncs.py", line 34, in
from spyder_kernels.py3compat import getcwd, pickle, PY2, to_text_string
File "C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\py3compat.py", line 356
c exec(code, globals, locals)
^
IndentationError: expected an indented block
None.
But I will google it.

The issue solved.
The first try:
After I reset the Spyder with the command in Anaconda Prompt.
spyder --reset
then restarted Anaconda Navigator.
The issue is NOT solved.
The second try:
After that, I read the error messages carefully.
I found that there is and indentation error in
C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\py3compat.py, line 356 c exec(code, globals, locals) ^ IndentationError: expected an indented block
Then I open the
C:\Users\user\anaconda3\lib\site-packages\spyder_kernels\py3compat.py"
with VSC (Visual Studio Code)
Then modify the line in the file.
c exec(code, globals, locals)
to
exec(code, globals, locals)
Save it and restart Anaconda Navigator.
Then the issue is solved.
I think the reason is that, with no purpose, I modify the line
exec(code, globals, locals)
to
c exec(code, globals, locals)

Related

Spyder Python IDE unable to start consolle

today, after a restart of my editor, I discovered that it is not able any more to run the consolle (using it on a daily since years).
In the consolle the following message appears:
Traceback (most recent call last):
File "C:\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\lib\site‑packages\spyder_kernels\console\__main__.py", line 23, in
start.main()
File "C:\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 253, in main
import_spydercustomize()
File "C:\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 43, in import_spydercustomize
import spydercustomize
ModuleNotFoundError: No module named 'spydercustomize'
My version of python is:
Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
and from a Python prompt I can see this:
>>> import spyder
>>> spyder.__version__
'4.2.5'
>>>
Anybody has an idea of what could have happened and how to fix this without reinstalling everything?
P.S. I noticed that the substrings "site‑packages" in the message from the consolle contains a character alike "-" that is not interpreted by the windows file explorer (it can't find the folder). It looks like to be another kid of minus sign. The folder "C:\Anaconda3\Lib\site-packages\spyder_kernels\customize" and its content are actually present on my PC

Pip not working; from 'ImportError: No module named urllib3' to non-admin windows user

I am facing some problems with pip. The original error message in my command prompt (windows, Python 2.7.14 and this is the version I must keep) when typing for instance pip was
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "c:\python27\lib\site-packages\pip\__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "c:\python27\lib\site-packages\pip\_vendor\requests\__init__.py", line 62, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "c:\python27\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
My journey to solve/explore the problem:
This happend no matter which of the following prompt commands I was trying
pip
pip --version
pip list
pip freeze
pip install --upgrade requests
pip install urllib3
Other commands might have change the error message a little bit in terms of the files listed like
python -m pip install --upgrade pip
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "C:\Python27\lib\runpy.py", line 111, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "C:\Python27\lib\site-packages\pip\__init__.py", line 21, in <module>
from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
File "C:\Python27\lib\site-packages\pip\_vendor\requests\__init__.py", line 62, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
I have checked the following (according to several suggestions I found in related questions on stackoverflow)
a pip application can be found in C:\Python27\Scripts
dont have something called PYTHONPATH in system variables only Path
C:\Python27\Scripts is listed in system variables>Path
anaconda was installed by the user before me. I uninstalled as apparently this could cause troubles and deleted all remaining .condarc files,./conda & conda folders as well as the system variable>Path listing.
I have tried the solution which was voted for here by downloading and running python get-pip.py. This is the error message:
>python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 23974, in <module>
main()
File "get-pip.py", line 188, in main
tmpdir = tempfile.mkdtemp()
File "C:\Python27\lib\tempfile.py", line 331, in mkdtemp
dir = gettempdir()
File "C:\Python27\lib\tempfile.py", line 275, in gettempdir
tempdir = _get_default_tempdir()
File "C:\Python27\lib\tempfile.py", line 200, in _get_default_tempdir
with _io.open(fd, 'wb', closefd=False) as fp:
AttributeError: 'module' object has no attribute 'open'
I was told there were some problems noticed before: The computer has 2 users, an administrator and an additional user with '(user)' in its name. I was told that it was not possible to install anaconda for that user - it was installed by the administrator for all users but in the end spyder for instance and the anaconda prompt could only be ran as administrator, too. So I am not sure if there is a problem in general with the user setup?!
I ran the command prompt as administrator and pip --version worked
pip 9.0.1 from c:\python27\lib\site-packages (python 2.7)
So I ran python -m pip install --upgrade pip as administrator, opened the command prompt again (not as administrator and now the new error is
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
File "c:\python27\lib\site-packages\pip\_internal\cli\main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "c:\python27\lib\site-packages\pip\_internal\cli\autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "c:\python27\lib\site-packages\pip\_internal\cli\main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "c:\python27\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 25, in <module>
from pip._internal.cli.progress_bars import BAR_TYPES
File "c:\python27\lib\site-packages\pip\_internal\cli\progress_bars.py", line 12, in <module>
from pip._internal.utils.logging import get_indentation
File "c:\python27\lib\site-packages\pip\_internal\utils\logging.py", line 18, in <module>
from pip._internal.utils.misc import ensure_dir
File "c:\python27\lib\site-packages\pip\_internal\utils\misc.py", line 21, in <module>
from pip._vendor import pkg_resources
File "c:\python27\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 26, in <module>
import zipfile
File "c:\python27\lib\zipfile.py", line 501, in <module>
class ZipExtFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'
Tried step 3 again, same outcome
Now I am frustrated and I am hoping for help because I am not super experienced and I don't want to mess up things even more (probably already did by uninstalling anaconda).
Thank you for helping!
PS: I can not exclude that I did not miss the correct solution for this problem, as several topics are addressing pip and urllib3 already, however I have tried my best to cover all suggestions. I apologize if there is already a similar topic solving this problem out there.

Unable to open jupyter notebook using pip on windows

C:\Users\user>jupyter notebook
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 197, in run_module_as_main
return run_code(code, main_globals, None,
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\Scripts\jupyter-notebook.EXE_main.py", line 4, in
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\notebook\notebookapp.py", line 47, in
from zmq.eventloop import ioloop
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\zmq_init.py", line 125, in
from zmq import backend
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\zmq\backend_init.py", line 32, in
raise original_error from None
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\zmq\backend_init_.py", line 27, in
_ns = select_backend(first)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\zmq\backend\select.py", line 36, in select_backend
raise ImportError(f"Importing {name} failed with {e}") from e
ImportError: Importing zmq.backend.cython failed with builtins.type size changed, may indicate binary incompatibility. Expected 888 from C header, got 880 from PyObject
I had the same problem and was able to rectify it by uninstalling the Jupyter notebook version that didn't work for me(5.0, 4.8) and installing a version that did work (4.0). I couldn't find this exact problem online but similar problems have occurred with NumPy module installations also fixed with a different version installation.
try:
pip uninstall notebook
pip install notebook==4.0

No module named 'tokenize'

Trouble with anaconda:
Error message below.
Reason why I think this is happening:
Accidentally deleted some files
I tried to uninstall Anaconda, and reinstall, however, when reinstalling - installer says Anaconda already installed, hence, not able to get Anaconda working.
Scanned through the net and stackoverflow, but unable to find an answer. Error message below:
"
Traceback (most recent call last):
File "/miniconda3/bin/conda", line 13, in <module>
sys.exit(main())
File "/miniconda3/lib/python3.7/site-packages/conda/cli/main.py", line 149, in main
from ..exceptions import conda_exception_handler
File "/miniconda3/lib/python3.7/site-packages/conda/exceptions.py", line 10, in <module>
from logging import getLogger
File "/miniconda3/lib/python3.7/logging/__init__.py", line 26, in <module>
import sys, os, time, io, traceback, warnings, weakref, collections.abc
File "/miniconda3/lib/python3.7/traceback.py", line 5, in <module>
import linecache
File "/miniconda3/lib/python3.7/linecache.py", line 11, in <module>
import tokenize
ModuleNotFoundError: No module named 'tokenize' "

py2exe TypeError: coercing to Unicode: need string or buffer, NoneType found

Trying to get py2exe to compile a script for me that uses fiona.
Packages I use:
import os
import fiona
import sys
from PyQt5.QtGui import QIcon
from PyQt5 import QtCore, QtGui
from PyQt5.QtWidgets import *
Then I end up with the following error after:
D:/Temp/project/python setup.py py2exe
Traceback (most recent call last):
File "setup.py", line 9, in <module>
"excludes": ['bz2']
File "C:\Anaconda\lib\distutils\core.py", line 151, in setup
dist.run_commands()
File "C:\Anaconda\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Anaconda\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Anaconda\lib\site-packages\py2exe\build_exe.py", line 243, in run
self._run()
File "C:\Anaconda\lib\site-packages\py2exe\build_exe.py", line 296, in _run
self.find_needed_modules(mf, required_files, required_modules)
File "C:\Anaconda\lib\site-packages\py2exe\build_exe.py", line 1333, in find_needed_modules
os.path.walk(path, visit, packages)
File "C:\Anaconda\lib\ntpath.py", line 266, in walk
names = os.listdir(top)
TypeError: coercing to Unicode: need string or buffer, NoneType found
Cheers
You could try PyInstaller as an alternative. I was attempting to use py2exe but getting the exact same error you are getting. But then I installed PyInstaller (can be done through pip) and ran that and it worked straight away. Take care to remove any build/dist directories you have leftover from trying to use py2exe.
Note: I would have posted this as a comment as it in not a direct answer but I don't have enough rep.

Resources