Sphinx Autodoc not importing properly - python

As the title says I am using Sphinx to generate documentation for a python library and using the auto doc functions.
The problem I am having is that the autodoc importer does not properly import the libraries.
Traceback (most recent call last):rs/user
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 4, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 3, in <module>
from gt import Model, EMAIL_FROM, EMAIL_HOST
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 5, in <module>
from lib import response
ImportError: cannot import name response
Traceback (most recent call last):json
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):messages
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
ImportError: No module named helper
Traceback (most recent call last):request
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):ser
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/models.py", line 6, in <module>
import gt
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 7, in <module>
from lib.decorators import valid_user
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 7, in <module>
from gt.modules.user.models import get_user_account, is_login_valid
ImportError: No module named modules.user.models
Traceback (most recent call last):ser
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 2, in <module>
from gt import app, TEMPLATES_PATH
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
ImportError: cannot import name views
I have tripled checked that the paths are correct and I am including them on the system path.
The thing that really gets me about this is that I can run the application just perfectly and all unit tests are passing with over 95% code coverage ... yet sphinx cannot import it.

That looks like an import loop. Try to organize your imports so that they don't depend on each other in a circle.
Alternatively, you can try to reorder them. Perhaps in helpers.py move line 3 to the bottom of the file, or something similar.

Related

gpustat returns curses errors

[notebook-0 workspace]$ gpustat
Traceback (most recent call last):
File "/home/sandbox/.local/bin/gpustat", line 5, in <module>
from gpustat import main
File "/home/sandbox/.local/lib/python3.7/site-packages/gpustat/__init__.py", line 7, in <module>
from .core import GPUStat, GPUStatCollection
File "/home/sandbox/.local/lib/python3.7/site-packages/gpustat/core.py", line 31, in <module>
class GPUStat(object):
File "/home/sandbox/.local/lib/python3.7/site-packages/gpustat/core.py", line 161, in GPUStat
term=Terminal(),
File "/home/sandbox/.local/lib/python3.7/site-packages/blessings/__init__.py", line 98, in __init__
self._init_descriptor)
_curses.error: setupterm: could not find terminfo database
When I run gpustat in my terminal, I get the above output.

Spyder throws AttributeError: 'NoneType' object has no attribute 'modules' when importing DBSCAN 3 times

I am using Spyder 3.3.2 and scikit-learn Version: 0.20.1. I am running a script that starts importing DBSCAN by:
from sklearn.cluster import DBSCAN
The first two times I run the script, it works ok. However,the third time I invariably get:
Traceback (most recent call last):
File "<ipython-input-3-f629b84de3e3>", line 1, in <module>
runfile('/home/mario/Documents/python_machine_learning_projects/test_for_question.py', wdir='/home/mario/Documents/python_machine_learning_projects')
File "/home/mario/.local/lib/python2.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 704, in runfile
execfile(filename, namespace)
File "/home/mario/.local/lib/python2.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 100, in execfile
builtins.execfile(filename, *where)
File "/home/mario/Documents/enerchemtek/python_machine_learning_projects/test_for_question.py", line 9, in <module>
from sklearn.cluster import DBSCAN
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/cluster/__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/cluster/spectral.py", line 15, in <module>
from ..metrics.pairwise import pairwise_kernels
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/metrics/__init__.py", line 7, in <module>
from .ranking import auc
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/metrics/ranking.py", line 36, in <module>
from ..preprocessing import label_binarize
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 6, in <module>
from ._function_transformer import FunctionTransformer
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/preprocessing/_function_transformer.py", line 5, in <module>
from ..utils.testing import assert_allclose_dense_sparse
File "/home/mario/.local/lib/python2.7/site-packages/sklearn/utils/testing.py", line 54, in <module>
from nose.tools import raises as _nose_raises
File "/home/mario/.local/lib/python2.7/site-packages/nose/__init__.py", line 1, in <module>
from nose.core import collector, main, run, run_exit, runmodule
File "/home/mario/.local/lib/python2.7/site-packages/nose/core.py", line 11, in <module>
from nose.config import Config, all_config_files
File "/home/mario/.local/lib/python2.7/site-packages/nose/config.py", line 9, in <module>
from nose.plugins.manager import NoPlugins
File "/home/mario/.local/lib/python2.7/site-packages/nose/plugins/__init__.py", line 185, in <module>
from nose.plugins.manager import *
File "/home/mario/.local/lib/python2.7/site-packages/nose/plugins/manager.py", line 418, in <module>
import pkg_resources
File "/home/mario/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 55, in <module>
from pkg_resources.extern import six
File "/home/mario/.local/lib/python2.7/site-packages/pkg_resources/extern/__init__.py", line 44, in load_module
mod = sys.modules[extant]
AttributeError: 'NoneType' object has no attribute 'modules'
If I run the script in a terminal by doing:
python MyScript.py
it all works ok, so it must be a problem with Spyder. Also, the error is replicated if I run a script that contains only that line of code.
Thanks in advance !

Cannot import flask

In command line python -c 'import flask'
Output:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/ubuntu/.local/lib/python2.7/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/home/ubuntu/.local/lib/python2.7/site-packages/werkzeug/__init__.py", line 151, in <module>
__import__('werkzeug.exceptions')
File "/home/ubuntu/.local/lib/python2.7/site-packages/werkzeug/exceptions.py", line 67, in <module>
from werkzeug._internal import _get_environ
File "/home/ubuntu/.local/lib/python2.7/site-packages/werkzeug/_internal.py", line 13, in <module>
import inspect
File "/usr/lib/python2.7/inspect.py", line 39, in <module>
import tokenize
File "/usr/lib/python2.7/tokenize.py", line 39, in <module>
COMMENT = N_TOKENS
NameError: name 'N_TOKENS' is not defined
How can I solve it?
Met this error in my flask project, although yesterday everything was fine.

ImportError: cannot import name 'request'

I am a windows user. I used the command pip install requests to have requests installed, and I also typedpip install urllib3 to have urllib3 installed. However, I am not able to run this code: from requests import request. I got a error like this:
Traceback (most recent call last):
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\__init__.py", line 27, in <module>
from . import urllib3
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "D:\Python\lib\http\client.py", line 71, in <module>
import email.parser
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
ImportError: cannot import name 'request'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "D:\Python\lib\site-packages\requests-2.13.0-py3.5.egg\requests\packages\__init__.py", line 29, in <module>
import urllib3
File "D:\Python\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "D:\Python\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "D:\Python\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import (
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 203, in load_module
mod = mod._resolve()
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "D:\Python\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "D:\Python\lib\http\client.py", line 71, in <module>
import email.parser
File "F:\eclipse\workspace\Overseascredit\email.py", line 1, in <module>
from requests import request
ImportError: cannot import name 'request'
I saw a lot of answers saying that there is another file with duplicate name that occur this error, however, I searched through the fold, I did found one. I even reinstalled my python, but I still got this error. Please help me.
Try using
from requests import Request
instead of
from requests import request

PyCharm Django test runner can't see django.sites (Runtime Error)

When I run manage.py test everything is working normally, but if run test with PyCharm Django Tests it gives me following error:
Error
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: order_form.tests
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/home/vagrant/project/order_form/tests.py", line 2, in <module>
from .models import Order
File "/home/vagrant/project/order_form/models.py", line 3, in <module>
from cms.models.pluginmodel import CMSPlugin
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/__init__.py", line 3, in <module>
from .pagemodel import * # nopyflakes
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/cms/models/pagemodel.py", line 6, in <module>
from django.contrib.sites.models import Site
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/contrib/sites/models.py", line 83, in <module>
class Site(models.Model):
File "/home/vagrant/.virtualenvs/env/lib/python3.4/site-packages/django/db/models/base.py", line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Yes, I've enabled 'django.contrib.sites' in INSTALLED_APPS and SITE_ID is set.
Any ideas?
I created local virtualenv and install same requirements — tests work fine with it.
Thanks, everybody for comments.

Categories