Spyder not launching from one of the Anaconda environments - python

I'm new to this. I have begun learning OpenCV with Python and following the course directions I've successfully created an Anaconda environment from which I can easily import CV2 and carry out my course. So far, I have experienced no problems in working with this environment.
Now, I would like to begin using Spyder which launches well from the default/base environment but does not launch from the "opencv-course" environment which I created. By contrast, Jupyter Labs and Notebooks launch well on either environment.
I've attempted to uninstall/reinstall Spyder using Administrator privileges when launching Anaconda, but to no avail.
Could anyone forward a suggestion?
Many thanks!
MD
The following error message is displayed:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\opencv-course\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\start.py", line 205, in main
mainwindow.main()
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\mainwindow.py", line 3734, in main
mainwindow = run_spyder(app, options, args)
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\mainwindow.py", line 3590, in run_spyder
main.setup()
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\app\mainwindow.py", line 977, in setup
'spyder.plugins.{}'.format(plugin_name))
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\__init__.py", line 14, in
from .plugin import Pylint as PLUGIN_CLASS
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\plugin.py", line 29, in
from spyder.plugins.pylint.confpage import PylintConfigPage
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\confpage.py", line 16, in
from spyder.plugins.pylint.widgets.pylintgui import PylintWidget
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\widgets\pylintgui.py", line 37, in
from spyder.plugins.pylint.utils import get_pylintrc_path
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\spyder\plugins\pylint\utils.py", line 16, in
import pylint.config
File "C:\ProgramData\Anaconda3\envs\opencv-course\lib\site-packages\pylint\config.py", line 54, in
import toml
ModuleNotFoundError: No module named 'toml'

After checking out this answer here:
Spyder failed to launch in Anaconda after update (4.1.2)
I've solved the problem by downgrading the version of Pylint from 2.5 to 2.4.4. It now works fine.
Many thanks!
MD

Related

Exception: Python.Runtime not found in pyinstaller

I have used pyinstaller many times before but I have never faced such issues
I am facing issues while converting .py to .exe using pyinstaller
What I have tried
I have installed pythonnet and opened the directory where pythonnet is stored but i could not find any dll file
I am using the following command
PyInstaller app.py --noconsole --icon=./images/Source.​ico
entire Traceback
Traceback (most recent call last):
File "c:\Users\ADMIN.DESKTOP-USLQ9P3\Desktop\jarvis\setup.py", line 3, in <module>
PyInstaller.__main__.run([
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 725, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 672, in build
exec(code, spec_namespace)
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\Desktop\jarvis\app.spec", line 6, in <module>
a = Analysis(['app.py'],
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
self.__postinit__()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 420, in assemble
self.graph.process_post_graph_hooks()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\depend\analysis.py", line 367, in process_post_graph_hooks
module_hook.post_graph()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\depend\imphook.py", line 447, in post_graph
self._load_hook_module()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\depend\imphook.py", line 408, in _load_hook_module
self._hook_module = importlib_load_source(
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\compat.py", line 598, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 962, in load_module
File "<frozen importlib._bootstrap_external>", line 787, in load_module
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-clr.py", line 40, in <module>
raise Exception(pyruntime + ' not found')
Exception: Python.Runtime not found
I have also install pythonnet but it is still not working neither can I find the dll
This is not a direct answer to your question, but I have had a lot of issues with pyinstaller myself in the past year. At this point I have the process perfected that I almost never have issues anymore. The key for me has been:
Do not use virtual environments (venv). I use a separate older computer specifically for pyinstaller. The computer only has basic python, pycharm and the libraries I need for my build installed to site packages. I install everything globally. I remove libraries I do not need.
If a library causes problems like you describe, try installing an older versio of said library.
To follow up:
Using pycharm does not work or pycharm in general does not work?
What I would recommend you do is what I do on a fresh computer:
Make sure you know which libraries your project requires. You could generate a requirements file: Automatically create requirements.txt
Uninstall python / anaconda from your computer completely incl all libs.
Reinstall python (not anaconda as it has way to many libraries) and click yes if installer asks you to add to path. Install pycharm community edition if you do not have it.
Install pyinstaller and other libs you need, but install them globally! I recommend using pycharm. Settings>yourproject>python interpreter>little plus icon>libraries you need. IMPORTANT: CHOOSE TO INSTALL TO SITE PACKAGE DIRECTORY:
Go to terminal in pycharm and type: pyinstaller --onefile my_python_file.py
You should now get an .exe file. in a dist folder in the directory of your file.
NOTE: the above should not be necessary and pyinstaller can work with virtual environments, but I have found it to be the most reliable way to use pyinstaller.
Try installing py2exe. This program also bundles python programs into .exe files, and I have used it for one of my games. To install this program, simply type into the command line:
python -m pip install py2exe
For more resources on py2exe, check out these links:
http://www.py2exe.org/
https://github.com/py2exe/py2exe
You should reinstall python and add it to your path, that might help you. There are lot of videos online you can refer to.

Cannot load German BERT model in spaCy

Here is my problem: I am working on the German text classification project. I use spacy for that and decided to fine-tune its pretrained BERT model to get better results. However, when I try to load it to the code, it shows me errors.
Here is what I've done:
Installed spacy-transformers: pip install spacy-transformers
Downloaded German BERT model: python -m spacy download de_trf_bertbasecased_lg. It was downloaded successfully and showed me: ✔ Download and installation successful
You can now load the model via spacy.load('de_trf_bertbasecased_lg')
Wrote the following code:
import spacy
nlp = spacy.load('de_trf_bertbasecased_lg')
And the output was:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
nlp = spacy.load('de_trf_bertbasecased_lg')
File "C:\Python\Python37\lib\site-packages\spacy\__init__.py", line 30, in load
return util.load_model(name, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 164, in load_model
return load_model_from_package(name, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 185, in load_model_from_package
return cls.load(**overrides)
File "C:\Python\Python37\lib\site-packages\de_trf_bertbasecased_lg\__init__.py", line 12, in load
return load_model_from_init_py(__file__, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 228, in load_model_from_init_py
return load_model_from_path(data_path, meta, **overrides)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 196, in load_model_from_path
cls = get_lang_class(lang)
File "C:\Python\Python37\lib\site-packages\spacy\util.py", line 70, in get_lang_class
if lang in registry.languages:
File "C:\Python\Python37\lib\site-packages\catalogue.py", line 56, in __contains__
has_entry_point = self.entry_points and self.get_entry_point(name)
File "C:\Python\Python37\lib\site-packages\catalogue.py", line 140, in get_entry_point
return entry_point.load()
File "C:\Python\Python37\lib\site-packages\importlib_metadata\__init__.py", line 94, in load
module = import_module(match.group('module'))
File "C:\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Python\Python37\lib\site-packages\spacy_transformers\__init__.py", line 1, in <module>
from .language import TransformersLanguage
File "C:\Python\Python37\lib\site-packages\spacy_transformers\language.py", line 5, in <module>
from .util import is_special_token, pkg_meta, ATTRS, PIPES, LANG_FACTORY
File "C:\Python\Python37\lib\site-packages\spacy_transformers\util.py", line 2, in <module>
import transformers
File "C:\Python\Python37\lib\site-packages\transformers\__init__.py", line 20, in <module>
from .file_utils import (TRANSFORMERS_CACHE, PYTORCH_TRANSFORMERS_CACHE, PYTORCH_PRETRAINED_BERT_CACHE,
File "C:\Python\Python37\lib\site-packages\transformers\file_utils.py", line 37, in <module>
import torch
File "C:\Python\Python37\lib\site-packages\torch\__init__.py", line 81, in <module>
ctypes.CDLL(dll)
File "C:\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
If I run the same code in PyCharm, it also shows me these two lines before all of those above:
2020-05-19 18:00:55.132721: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not
load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2020-05-19 18:00:55.132990: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart
dlerror if you do not have a GPU set up on your machine.
If I got it right, these two lines complain that I don't have a GPU. However, according to the docs, I should be able to use BERT even without GPU.
So I am really stuck right now and looking for your help.
I should also mention, that I used de_core_news_sm model before and it worked fine.
I have also already tried several solutions, but none of them worked. I tried:
this and this. I have also tried to uninstall all spacy-related libraries and installed them again. Didn't help either.
I am working with:
Windows 10 Home
Python: 3.7.2
Spacy: 2.2.4
Spacy-transformers: 0.5.1
Would appreciate any help or advice!
It's probably a problem with your installation of torch. Start in a clean virtual environment and install torch using the instructions here with CUDA as None: https://pytorch.org/get-started/locally/. Then install spacy-transformers with pip.
Try:
python -m spacy download de_trf_bertbasecased_lg
python -m spacy download de_trf_bertbasecased_lg-2.2.0
python -m spacy link de_trf_bertbasecased_lg
python -m spacy link de_trf_bertbasecased_lg-2.2.0
Or:
python -m spacy download de
python -m spacy.de.download all
Or download directly from:
https://deepset.ai/german-bert
Then load:
nlp = spacy.load(r'Path_To_File\de_trf_bertbasecased_lg-2.2.0')

Cannot access python shell from virtualenv and Django

I'm on Windows 10.
I tried to install channels to use websockets with Django but it doesn't work. I got the following error :
Failed building wheel for Twisted
I have still not succeeded to install channels.
But now I have a new problem, I can no anymore access Python shell from my virtual environment that I use for Django.
(myproject) D:\Django\mysite>py manage.py shell
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\kevin\Envs\myproject\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'channels'
I have no idea to solve my problem ... Someone could bring me help ?
Try install channels by using pip install channels
then run shell again
Seems like you broke something when you tried to install channels. From the spares information I guess that easiest course of action is to simply use a new virtual environment. After all that is the point of a virtual environment, if it breaks you can just rebuild it.
Manually fixing the virtual environment usually (this is my personal experience) takes more time then just setting up a new one.
For your installation trouble we need more info and you should open a new question.
So just deactivate your current environment (this might help), delete it and set up a new one.
Keep in mind that this will only bring the shell back and give you a "fresh start". Your installation problem will usually not disappear!

pyinstaller 3.2 with django 1.10.1

System: windows 7 64 bit, python 3.5, anaconda 3 (64 bit) , django 1.10.1
I'm trying to compile my django project in 2 ways:
First:
[Anaconda3] c:\compilation\Gui>pyinstaller --name=gui --exclude-module=PyQt4 --exclude-module=matplotlib --clean --win-private-assemblies manage.py
Second according to this soloution:
[Anaconda3] c:\compilation\Gui>pyinstaller --name=gui --exclude-module=PyQt4 --exclude-module=matplotlib --clean --win-private-assemblies --runtime-hook=pyi_rth_django.py manage.py
When I try to run the output:
c:\compilation\Gui\dist\gui>gui.exe runserver
I get (for the 2 versions I get the same output):
c:\compilation\Gui\dist\gui>gui.exe runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x00000000044E9D90>
Traceback (most recent call last):
File "site-packages\django\utils\autoreload.py", line 226, in wrapper
File "site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
File "site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
File "site-packages\django\utils\six.py", line 685, in reraise
File "site-packages\django\utils\autoreload.py", line 226, in wrapper
File "site-packages\django\__init__.py", line 27, in setup
File "site-packages\django\apps\registry.py", line 85, in populate
File "site-packages\django\apps\config.py", line 116, in create
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'django.contrib.admin.apps'
Please advice.
What is your files layout? According to these pyinstaller docs https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Executable-From-Django there could be two solutions.
run your command from parent directory, i.e. instead of
c:\compilation\Gui>pyinstaller --name=gui manage.py
do
c:\compilation>pyinstaller --name=gui Gui\manage.py
try to add import django.contrib.admin.apps to your manage.py and make sure it exists
report bug
To fix the "ImportError: No module named django.contrib.admin.apps" problem you have to create a directory, let's call it "your_project/other_hooks".
Inside that directory create a file called hook-django.contrib.py with this content:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('django.contrib')
Now call pyinstaller in this way:
pyinstaller --name=yourProject --additional-hooks-dir=your_project\other_hooks your_project\manage.py
While you can use any name for the directory, the file name is mandatory, it has to be "hook-django.contrib.py".
Hope this helps.
References:
https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Executable-From-Django
https://github.com/pyinstaller/pyinstaller/issues/2332
https://pythonhosted.org/PyInstaller/hooks.html#how-a-hook-is-loaded

Ansible - "NameError: name 'urllib2' is not defined"

Getting this below error while trying to run ansible(version >2) with python 3.5.2
I have looked into the github issues terming it as resolved, but can't sort out what needs to be done. https://github.com/ansible/ansible/issues/16013
How to resolve this?
virtual#xxxxxxxxxx:~/ansible-spike> ansible all -m ping -vvv
Using /home/virtual/ansible-spike/ansible.cfg as config file
ERROR! Unexpected Exception: name 'urllib2' is not defined
the full traceback was:
Traceback (most recent call last):
File "/home/virtual/.pyenv/versions/3.5.2/bin/ansible", line 92, in <module>
exit_code = cli.run()
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/cli/adhoc.py", line 193, in run
result = self._tqm.run(play)
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/executor/task_queue_manager.py", line 202, in run
self.load_callbacks()
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/executor/task_queue_manager.py", line 171, in load_callbacks
for callback_plugin in callback_loader.all(class_only=True):
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/plugins/__init__.py", line 368, in all
self._module_cache[path] = self._load_module_source(name, path)
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/plugins/__init__.py", line 319, in _load_module_source
module = imp.load_source(name, path, module_file)
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/plugins/callback/hipchat.py", line 32, in <module>
from ansible.module_utils.urls import open_url
File "/home/virtual/.pyenv/versions/3.5.2/lib/python3.5/site-packages/ansible/module_utils/urls.py", line 330, in <module>
if hasattr(httplib, 'HTTPSConnection') and hasattr(urllib2, 'HTTPSHandler'):
NameError: name 'urllib2' is not defined
Urllib2 is specific to Python v2.
Urllib2 documentation at http://docs.python.org/library/urllib2.html:
The urllib2 module has been split across several modules in Python 3.0
named urllib.request and urllib.error.
I don't think Ansible is compatible with Python 3 yet.
The ansible python API does not support Python 3. The PyPI page lists only 2.6 and 2.7 .
Ansible is currently not able to run with Python3. That is also stated in the linked Github Issue.
If you are using
import urllib2
Instead, you can call the library as
import urllib.request
Then use it like
urllib.request.urlopen('your url goes here')
This should get rid of the error you are getting

Categories

Resources