Spyder (Anaconda) Not Running because of some errors - python

When I am trying to run the spyder (Anaconda) I am getting the following Error:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\start.py", line 205, in main
mainwindow.main()
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3651, in main
mainwindow = run_spyder(app, options, args)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3526, in run_spyder
main.setup()
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 945, in setup
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\plugin.py", line 46, in
from spyder.plugins.ipythonconsole.widgets import (ClientWidget,
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\__init__.py", line 16, in
from .debugging import DebuggingWidget
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\debugging.py", line 13, in
import pdb
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 138, in
class Pdb(bdb.Bdb, cmd.Cmd):
AttributeError: module 'cmd' has no attribute 'Cmd'
Can someone please health me to resolve this issue?

I have created a file with the name cmd.py. After deleting the file (or rename the file), my problem got solved.

Do you happen to have a file named cmd.py in the same directory as the file you are trying to execute?
Cause If you are, then import cmd would not import the right python module. Instead, it would import your created "cmd.py" file.
I too faced this issue cause I had a file named "cmd.py" along with my python scripts and it would import that whenever I said import cmd. Renaming it helped me solve the issue

Related

Why do my Pyinstaller created .exe files keep crashing on start-up

I have written different Python projects using PyQT5 and now trying to create their .exe files to make them standalone and executable but whenever I try using pyinstaller command:
pyinstaller --onefile myfile.py
the created .exe file always crashes. But in my other system, when create .exe files using the same pyinstaller command, the .exe files run well. So why am I having issues creating .exe files in this particular system? What could be wrong please? My files contains python classes of different widgets and the scripts run well in the editors, the GUIs open well when run from the editor but not as a standalone. Now I want them as standalone. I have also used auto-py-to-exe, same issue. How do I resolve this?
I am also attaching a screenshot of the pyinstaller details of both systems to this post. The two descriptions (details) are captured in the photo, the one on the larger screen is the one of the system I am having issues with, while the smaller display is the one of the system where the .exe files are created and runs successfully without any issue. I noticed in the one running successfully, the attributes are more compared to the one having an issue. The one without an issue has [recursive-copy meta data],[splash image file], [disable windowed traceback], [--target -architecture arch], [-codesign identity IDENTITY], [--osx-entitlements-filename-FILENAME] whereas the pyinstaller having issues in my other system does not have it.
The below is some of the errors I get.
Traceback (most recent call last):
File "f:\installed program files\python\python 39\lib\site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "f:\installed program files\python\python 39\lib\importlib\util.py", line 2, in <module>
from . import abc
File "f:\installed program files\python\python 39\lib\importlib\abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1359, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
Remainder of file ignored
Error processing line 1 of f:\installed program files\python\python
39\lib\site-packages\zope.event-4.5.0-py3.6-nspkg.pth:
Traceback (most recent call last):
File "f:\installed program files\python\python 39\lib\site.py", line
169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "f:\installed program files\python\python 39\lib\importlib\util.py", line 2, in <module>
from . import abc
File "f:\installed program files\python\python 39\lib\importlib\abc.py",
line 17, in <module>
from typing import Protocol, runtime_checkable
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1359, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
I have found a solution to it and hope others having similar issue who come across this post will use the suggestion too. I had to pip uninstall typing. i.e
pip uninstall typing
This helps fix whatever issue there was and my .exe files run well using pyinstaller without crashing. After uninstalling typing module, run the pyinstaller command again to create your executables.

Py to exe pyinstaller import errors

Im trying to convert a single file python script/project into an exe using pyinstaller
Even thought pyinstaller converts the script the .exe will run and throw this
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[16676] Failed to execute script main
I'm stumped , through my trial and erroring i figured that when i replace pynput with a module like random the convertion works fine , but i need it to work with pynput
please help , thanks in advance!
Authors made some changes which i feel broke the reference.
so instead of package it is referring file.
- backend = backend(__package__)
+ backend = backend(__name__)
pls try to downgrade your package and check that your app still works.
pip install pynput==1.6.8
then your command like following would work.
pyinstaller --onefile build_pkg_for.py

Spyder :An error ocurred while starting the kernel

The ipython console is constantly throwing this error and I tried :
updating spyder
Uninstalling and reinstalling anaconda
Reading people's response on how they tried to fix it
But still I could not fix this.
Traceback (most recent call last):
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\console\__main__.py", line 11, in
start.main()
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 287, in main
import_spydercustomize()
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 39, in import_spydercustomize
import spydercustomize
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\spyder_kernels\customize\spydercustomize.py", line 27, in
from IPython.core.getipython import get_ipython
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\IPython\__init__.py", line 54, in
from .core.application import Application
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\IPython\core\application.py", line 23, in
from traitlets.config.application import Application, catch_config_error
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\traitlets\config\__init__.py", line 6, in
from .application import *
File "C:\Users\bbachegowda\AppData\Local\Continuum\anaconda3\lib\site‑packages\traitlets\config\application.py", line 10, in
import json
File "C:\Users\bbachegowda\json.py", line 12
source = response.read()
^
IndentationError: expected an indented block
The module name resolution is described in https://docs.python.org/3/tutorial/modules.html#the-module-search-path:
When a module named spam is imported, the interpreter first searches
for a built-in module with that name. If not found, it then searches
for a file named spam.py in a list of directories given by the
variable sys.path.
It looks like for some reason, the built-in module json is not found and that python looks into the path where C:\Users\bbachegowda\json.py is. So you should reinstall python to fix the built-in module json.
Had the same problem with Spyder when installing WinPython, version: WPy64-3.7.4.1.
However previous version: WPy64-3.7.4.0 works fine.

Python suddenly has error: "No module named unittest." I'm not running a unit test

I have a Django application, which very suddenly started giving me an error. I made a code change, restarted the application, and now I can't get rid of this error. I really don't think that I did anything else in between the two runs.
The error is ImportError: "No module named unittest" I don't know if it thinks it should be running a unit test or if this just happens to be the first thing to fail.
I have tried running it both from Eclipse and from the CMD line with manage.py runserver. Same error. (This is an update. previously I had only tried from Eclipse.) A brand-new project made in Eclipse has the same error.
This happens with any web application (using runserver), so it's not my code. I also reverted back to older code that worked fine before.
I have tried restarting my computer.
I am able to run "regular'(not a web application) python programs from the cmd line. So it does find Python.
I honestly have no idea what to do at this point, except to reinstall Python, which I'd like to avoid. Anyone?
NEW Stack trace (Update: previous was from Eclipse and just showed pydev errors. Run from cmd line it shows more python.)
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x02FE2710>>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 93, in inner_run
self.validate(display_num_errors=True)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 75, in _populate
self.load_app(app_name)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 18, in <module>
from django.contrib.auth.hashers import (
File "C:\Python27\lib\site-packages\django\contrib\auth\hashers.py", line 8, in <module>
from django.test.signals import setting_changed
File "C:\Python27\lib\site-packages\django\test\__init__.py", line 6, in <module>
from django.test.testcases import (TestCase, TransactionTestCase,
File "C:\Python27\lib\site-packages\django\test\testcases.py", line 35, in <module>
from django.test import _doctest as doctest
File "C:\Python27\lib\site-packages\django\test\_doctest.py", line 104, in <module>
import unittest, difflib, pdb, tempfile
ImportError: No module named unittest
Well, don't know if I'd call it an answer, but I reinstalled Python and now it's working. Now I just have to reinstall my 10 or so libraries to fix the runtime errors.
unittest module is integral part of python, which causes import error when django tries to import it. You must have somehow deleted some python package, or have corrupted installation.

Freezing (.exe) a traitsUI program, realistically feasible?

I'm trying to freeze with either cx_freeze or pyInstaller a TraitsUI program that makes use of Chaco, Traits, TraitsUI and to a lesser extent mayavi (could actually be taken out). I need this to run on mac, linux, ubuntu so am avoiding py2exe. I've intentionally uninstalled pyqt and pyside so that only the wx backend is available.
Using cx_freeze, I encountered and reported a bug, so pyInstaller seems to be getting me the furthest. It generated an .exe file, but when I run the file I get warnings and an error. To generate the .exe file I did:
pyinstaller --onefile --name=pameapp pamemain.py
pyinstaller pameapp.exe
Upon running, the warnings are:
Warning: Unable to import the wx backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named wx.init
Warning: Unable to import the qt4 backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named init
Warning: Unable to import the null backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named null.init
In addition, I get the following error:
Traceback (most recent call last):
File "<string>", line 8, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.api", line 35, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors", line 22, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.api", line 10, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.code_editor", line 36, in <module>
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.code_editor", line 48, in ToolkitEditorFactory
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traits.traits", line 487, in __call__
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traits.traits", line 1191, in Color
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.toolkit_traits", line 7, in ColorTrait
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.toolkit", line 137, in toolkit
traits.trait_errors.TraitError: Could not find any UI toolkit called 'null'
pyface probably has a lot of dynamic imports, so this must be a problem encountered by anyone who tries to freeze ETS. Is there a single fix to get this working?
Considering the older stuff floating around the web on success rates to freezing an ETS program, is it even worth further investment? To us, having people avoid configuring python for this application would be a huge plus.
Thanks.
Pyface.toolkit you are using is using dynamic import:
def import_toolkit(tk):
try:
# Try and import the toolkit's pyface backend init module.
be = 'pyface.ui.%s.' % tk
__import__(be + 'init')
except:
raise
return be
So pyinstaller is not able to detect this. Check with python -v b.py 2>&1 | grep imp what is the specific import and add hook file (hook-.py) with proper hiddenimports list.
However I've did some tests in local and I am not able to do working test schema with __import__. It's strange as I did some debugging and I found that hiddenimport is added but still not usable.

Categories

Resources