ModuleNotFoundError: No module named 'context' - django

I get the following error when I try to run a pyVows test:
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\unittest\loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "C:\Program Files\Python38\lib\unittest\loader.py", line 377, in _get_module_from_name
__import__(name)
File "D:\Programmierung\Python-Projekte\JourneyMap\JourneyMap\tests.py", line 2, in <module>
from django_pyvows.context import DjangoHTTPContext
File "C:\Users\malo0\AppData\Roaming\Python\Python38\site-packages\django_pyvows\__init__.py", line 11, in <module>
from context import DjangoContext, DjangoHTTPContext
ModuleNotFoundError: No module named 'context'
I installed pyVows and django-pyvows Am I missing something? I found no helpful documentation
REQUESTED EDIT:
from pyvows import Vows, expect
from django_pyvows.context import DjangoHTTPContext
# Create your tests here.
#Vows.batch
class LanguageTest(Vows.Context):
class LanguageSelectIntegrationTest(DjangoHTTPContext):
def topic(self):
return self.get('/')
def test(self, topic):
# Test will be here
pass

Related

How to import Webots controller in a Ros-python script

I want to write a controller in Python and trying to import Webots controller library:
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from time import sleep
from controller import Robot
and get the error
Traceback (most recent call last):
File "./mine_controller.py", line 6, in <module>
from controller import Robot
File "/snap/webots/current/usr/share/webots/lib/controller/python27/controller.py", line 17, in <module>
_controller = swig_import_helper()
File "/snap/webots/current/usr/share/webots/lib/controller/python27/controller.py", line 16, in swig_import_helper
return importlib.import_module('_controller')
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: libCppController.so: cannot open shared object file: No such file or directory
My environmental variables :
PYTHONPATH=/snap/webots/current/usr/share/webots/lib/controller/python27:/home/boand/workspace_ros/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages
LD_LIBRARY_PATH=/home/boand/workspace_ros/devel/lib:/opt/ros/melodic/lib:/snap/webots/current/usr/share/webots/lib
It seems your LD_LIBRARY_PATH is wrong, /snap/webots/current/usr/share/webots/lib should be replaced by /snap/webots/current/usr/share/webots/lib/controller.

ImportError: cannot import name game

I am getting the error - ImportError: cannot import name
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/rng/PycharmProjects/ex47/tests/ex47_tests.py", line 2, in <module>
from ex47 import game
ImportError: cannot import name game
Here's my directory structure for reference:
Within the folder I have two folders and two python files:
./ex47 ./tests init.py setup.py
./ex47:
game.py init.py
./tests:
ex47_tests.py init.py
the ex47_tests.py looks like this:
from nose.tools import *
from ex47 import game
I have read and tried the export PYTHONPATH=. on the directory above to no avail. Thoughts?

Orange Data Mining - Pythonw.exe has stopped working - errors

I have installed the complete Orange Data mining windows package.
When starting from the program Icon the Orange Canvas will show up but at some point the error message Pythonw.exe has stopped working will appear
As pointed out in some other posts I started from the command line
C:\Python27>python.exe -m Orange.OrangeCanvas.main -l3
and get following log - any recommendations what to do?
UPDATE: just found a log in the C:\Users\nnnn\AppData\Roaming\orange\OrangeCanvasQt4\outputLog.html
There were problems importing the following widgets:
OWC45Tree: c45 is not found
OWRScript: No module named rpy2.robjects
OWLinProj3D: No module named OpenGL
OWNxExplorer3D: No module named OWNxExplorerQt
OWScatterPlot3D: No module named OpenGL
OWSphereviz3D: No module named OpenGL
The following widgets could not be imported and will not be available: OWSphereviz3D, OWScatterPlot3D, OWLinProj3D, OWC45Tree, OWNxExplorer3D.
The following prototype widgets could not be imported and will not be available: OWRScript.
Unhandled exception of type NameError occured at 20:58:30:
Traceback:
File: OWWidget.py, line 178 in reportAndFinish
Code: self.sendReport()
File: OWQuickSelect.py, line 121 in sendReport
Code: if self.selectedAttribute and 0 <= self.selectedAttribute[0] <= len(self.attributes) else _("(none)")),
NameError: global name '_' is not defined
C:\Python27>python.exe -m Orange.OrangeCanvas.main -l3
Setting up Canvas main window.
'CanvasScene(objectName='', ...)' intitialized.
Setting registry 'None on 'CanvasScene(objectName='', ...)'.
'CanvasScene(objectName='', ...)' cleared.
'CanvasScene(objectName='', ...)' intitialized.
Setting registry 'None on 'CanvasScene(objectName='', ...)'.
Setting scheme '<Orange.OrangeCanvas.scheme.widgetsscheme.WidgetsScheme object at 0x04C12E40>' on 'CanvasScene(objectName='', ...)'
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Visualize\\OWLinProjGraph.py'.
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Visualize\\OWParallelGraph.py'.
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Visualize\\OWPolyvizGraph.py'.
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Visualize\\OWScatterPlotGraph.py'.
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Visualize\\OWSieveMultigramGraph.py'.
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Visualize\\OWSurveyPlotGraph.py'.
Could not import 'Orange.OrangeWidgets.Classify.OWC45Tree'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\Classify\OWC45Tree.py", line 35, in <module>
raise ImportError("c45 is not found")
ImportError: c45 is not found
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Classify\\OWNomogramGraph.py'.
Could not import 'Orange.OrangeWidgets.Prototypes.OWRScript'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\Prototypes\OWRScript.py", line 12, in <module>
import Orange.utils.r as r
File "C:\Python27\lib\site-packages\Orange\utils\r.py", line 19, in <module>
import rpy2.robjects as robjects
ImportError: No module named rpy2.robjects
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\Prototypes\\OWTimeDataVisualizerGraph.py'.
Could not import 'Orange.OrangeWidgets.VisualizeQt.OWLinProj3D'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\VisualizeQt\OWLinProj3D.py", line 7, in <module>
from plot.owplot3d import *
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owplot3d.py", line 28, in <module>
from owopenglrenderer import OWOpenGLRenderer
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owopenglrenderer.py", line 19, in <module>
import OpenGL
ImportError: No module named OpenGL
Could not import 'Orange.OrangeWidgets.VisualizeQt.OWLinProj3DPlot'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\VisualizeQt\OWLinProj3DPlot.py", line 3, in <module>
from plot.owplot3d import *
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owplot3d.py", line 28, in <module>
from owopenglrenderer import OWOpenGLRenderer
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owopenglrenderer.py", line 19, in <module>
import OpenGL
ImportError: No module named OpenGL
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\VisualizeQt\\OWLinProjGraphQt.py'.
Could not import 'Orange.OrangeWidgets.VisualizeQt.OWNxCanvas3D'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\VisualizeQt\OWNxCanvas3D.py", line 1, in <module>
from plot.owplot3d import OWPlot3D, GL_FLOAT, GL_LINES, GL_POINTS, glEnable, GL_PROGRAM_POINT_SIZE
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owplot3d.py", line 28, in <module>
from owopenglrenderer import OWOpenGLRenderer
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owopenglrenderer.py", line 19, in <module>
import OpenGL
ImportError: No module named OpenGL
Could not import 'Orange.OrangeWidgets.VisualizeQt.OWNxExplorer3D'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\VisualizeQt\OWNxExplorer3D.py", line 9, in <module>
from OWNxExplorerQt import OWNxExplorerQt
ImportError: No module named OWNxExplorerQt
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\VisualizeQt\\OWParallelGraphQt.py'.
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\VisualizeQt\\OWPolyvizGraphQt.py'.
Could not import 'Orange.OrangeWidgets.VisualizeQt.OWScatterPlot3D'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\VisualizeQt\OWScatterPlot3D.py", line 10, in <module>
from plot.owplot3d import *
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owplot3d.py", line 28, in <module>
from owopenglrenderer import OWOpenGLRenderer
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owopenglrenderer.py", line 19, in <module>
import OpenGL
ImportError: No module named OpenGL
Ignoring 'C:\\Python27\\lib\\site-packages\\Orange\\OrangeWidgets\\VisualizeQt\\OWScatterPlotGraphQt.py'.
Could not import 'Orange.OrangeWidgets.VisualizeQt.OWSphereviz3D'.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 296, in iter_widget_descriptions
module = asmodule(name)
File "C:\Python27\lib\site-packages\Orange\OrangeCanvas\registry\discovery.py", line 557, in asmodule
return __import__(module, fromlist=[""])
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\VisualizeQt\OWSphereviz3D.py", line 11, in <module>
from plot.owplot3d import *
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owplot3d.py", line 28, in <module>
from owopenglrenderer import OWOpenGLRenderer
File "C:\Python27\lib\site-packages\Orange\OrangeWidgets\plot\owopenglrenderer.py", line 19, in <module>
import OpenGL
ImportError: No module named OpenGL
Setting registry '<Orange.OrangeCanvas.registry.qt.QtWidgetRegistry object at 0x04CBAF60> on 'CanvasScene(objectName='', ...)'.
Created <class 'Orange.OrangeCanvas.help.provider.IntersphinxHelpProvider'> provider for Orange 2.7.8

Sphinx: Autodoc ImportError

I'm trying to auto generate the documentation for my Django project. The doctree gets generated on the html page but there is no documentation for any of the members within any of my modules. I keep running into this problem:
Running Sphinx v1.1.3
loading pickled environment... not yet created
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/admin.py", line 1, in <module>
from tool.models import All_alerts
File "/home/tim/Desktop/fqdn/mysite/tool/models.py", line 3, in <module>
from django.db import models
ImportError: No module named django.db
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/forms.py", line 1, in <module>
from django import forms
ImportError: No module named django
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/models.py", line 3, in <module>
from django.db import models
ImportError: No module named django.db
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page1urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page2urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page3urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page4urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/tests.py", line 1, in <module>
from django.test import TestCase
ImportError: No module named django.test
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/views.py", line 1, in <module>
from tool.models import Product
File "/home/tim/Desktop/fqdn/mysite/tool/models.py", line 3, in <module>
from django.db import models
ImportError: No module named django.db
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:7: WARNING: autodoc can't import/find module 'tool.admin', it reported error: "No module named django.db", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:15: WARNING: autodoc can't import/find module 'tool.forms', it reported error: "No module named django", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:23: WARNING: autodoc can't import/find module 'tool.models', it reported error: "No module named django.db", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:31: WARNING: autodoc can't import/find module 'tool.page1urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:39: WARNING: autodoc can't import/find module 'tool.page2urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:47: WARNING: autodoc can't import/find module 'tool.page3urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:55: WARNING: autodoc can't import/find module 'tool.page4urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:63: WARNING: autodoc can't import/find module 'tool.tests', it reported error: "No module named django.test", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:71: WARNING: autodoc can't import/find module 'tool.urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:79: WARNING: autodoc can't import/find module 'tool.views', it reported error: "No module named django.db", please check your spelling and sys.path
I've been scouring the web for any solutions. I tried rearranging the import statements within the modules but nothing is working.
sys.path.insert(0, os.path.abspath('/home/tim/Desktop/fqdn/mysite/tool/'))
All my modules are in the tool folder. Any help is desperately needed. Thanks!
Also, doesn't automodule encapsulate autofunction? So why would we ever use autofunction?
You should use MagicMock to simplify the dependencies.
In your conf.py:
from unittest.mock import MagicMock
import sys
MODULES = ['django']
for mod_name in MODULES:
sys.modules[mod_name] = MagicMock()

Mocking Django for plugin: can't find settings.py

I'm trying to write test for a django plugin called Dynamic Response (available on GitHub), but I'm having some issues. Using mock I'm trying to mock certain Django methods like render_to_response, (i'm not going to test django after all) but when I try to do so, i get an error message saying it can't find settings.py, which it shouldn't as this is a plugin to be used in other projects, not a project in itself. I've tried the following code:
class ResponseTest (unittest.TestCase):
#patch('dynamicresponse.response.render_to_response')
def test_is_testframework_working(self, render_to_response):
from dynamicresponse.response import SerializeOrRender
SerializeOrRender()
Which, as stated, gives an error message. Stubbing HttpResponse, HttpRedirect does not throw these errors...
gives the following stacktrace
Response (unittest.loader.ModuleImportFailure) ... ERROR
======================================================================
ERROR: response (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: response
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 252, in _find_tests
module = self._get_module_from_name(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
__import__(name)
File "/Users/skinney/Workspace/django-dynamicresponse/tests/response.py", line 5, in <module>
class ResponseTest (unittest.TestCase):
File "/Users/skinney/Workspace/django-dynamicresponse/tests/response.py", line 7, in ResponseTest
#patch('dynamicresponse.response.render_to_response')
File "/Users/skinney/Workspace/django-dynamicresponse/tests/mock.py", line 720, in patch
target = _importer(target)
File "/Users/skinney/Workspace/django-dynamicresponse/tests/mock.py", line 514, in _importer
thing = _dot_lookup(thing, comp, import_path)
File "/Users/skinney/Workspace/django-dynamicresponse/tests/mock.py", line 503, in _dot_lookup
__import__(import_path)
File "/Users/skinney/Workspace/django-dynamicresponse/dynamicresponse/response.py", line 3, in <module>
from django.shortcuts import render_to_response
File "/Library/Python/2.7/site-packages/django/shortcuts/__init__.py", line 10, in <module>
from django.db.models.manager import Manager
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/Library/Python/2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
You can't test django apps without any project (real or dummy, whatever) having its own settings file.