ImportError: cannot import name game - python-2.7

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?

Related

ModuleNotFoundError: No module named 'context'

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

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.

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()

Standalone Django application with pyinstaller on Windows

I need to package a (rather simple) django application into a standalone executable on windows. After some failed attempts with py2exe (I really don't understand why everybody recommends it for django, it seems extremely complicated to set up) I tried pyinstaller. It does package the application without complaining, but if I try to run it using myapp.exe runserver localhost:8000, I am getting the following error:
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_
module
exec(bytecode, module.__dict__)
File "...\build\ck\out00-PYZ.pyz\django.test", line 5, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_
module
exec(bytecode, module.__dict__)
File "...\build\ck\out00-PYZ.pyz\django.test.client", line 21, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_
module
exec(bytecode, module.__dict__)
File "...\build\ck\out00-PYZ.pyz\django.db", line 11, in <module>
File "...\build\ck\out00-PYZ.pyz\django.conf", line 52, in __getattr__
File "...\build\ck\out00-PYZ.pyz\django.conf", line 45, in _setup
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must eith
er define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
My manage.py script looks like this:
#!/usr/bin/env python
import os
import sys
import Cookie
import django.test
import HTMLParser
from django.conf import settings
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Why does it not recognize the environment variable and how can I fix that?
I solved it by importing django.test after the line
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")

ImportError: cannot import name array, when importing urllib2

I am getting below error when trying to import the urllib2:
>>> import urllib2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/usr/lib64/python2.7/httplib.py", line 69, in <module>
from array import array
ImportError: cannot import name array`
Any thoughts on it?
It seems you have a python program named "array.py" in you present working directory. If yes rename that python program or move it to some other directory.