Sphinx fails to import subpackages
I have a project directory structured like so:
|--sphinx
|--mypackage
|--__init__.py
|--core
|--__init__.py
|--program.py
|--foo.py
|--factory
|--__init__.py
|--basefactory.py
First, I run the sphinx-apidoc
with the following paramters from command line:
c:Debugsphinx>sphinx-apidoc -o "C:DebugSphinx" "C:DebugSphinxmypackage" -f --full
This creates the folder structure, .bat and .rst files, etc., within the "output" directory. Good so far.
When I try to run the make html
, I get errors/warnings, indicating:
WARNING: autodoc: failed to import module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.foo' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.program' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory.basefactory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
Other similar questions (1, 2, 3) suggest modifying the sys.path.insert
statement in the conf.py
file.
I have tried using:
sys.path.insert(0, os.path.abspath)
But the results are the same.
If I add the package's root path (sys.path.insert(0, 'c:debugsphinx')
, I get fewer errors from Sphinx, this time only related to thee subpackages core
and factory
:
WARNING: autodoc: failed to import module 'program' from module 'mypackage.core'; the following exception was raised:
No module named 'foo'
WARNING: autodoc: failed to import module 'basefactory' from module 'mypackage.factory'; the following exception was raised:
No module named 'core'
Ultimately, I can get this to produce the dox by inserting ALL of the paths in the conf.py
file:
sys.path.insert(0, 'c:debugsphinx')
sys.path.insert(0, 'c:debugsphinxmypackage')
sys.path.insert(0, 'c:debugsphinxmypackagecore')
sys.path.insert(0, 'c:debugsphinxmypackagefactory')
But it seems like I'm doing something wrong here. Is there a single path I can add to sys.path
that will let this work without import errors? Should I have to hardcode all of the paths to package/subpackages? Or if not, what am I doing wrong?
python python-3.x python-sphinx
|
show 3 more comments
I have a project directory structured like so:
|--sphinx
|--mypackage
|--__init__.py
|--core
|--__init__.py
|--program.py
|--foo.py
|--factory
|--__init__.py
|--basefactory.py
First, I run the sphinx-apidoc
with the following paramters from command line:
c:Debugsphinx>sphinx-apidoc -o "C:DebugSphinx" "C:DebugSphinxmypackage" -f --full
This creates the folder structure, .bat and .rst files, etc., within the "output" directory. Good so far.
When I try to run the make html
, I get errors/warnings, indicating:
WARNING: autodoc: failed to import module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.foo' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.program' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory.basefactory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
Other similar questions (1, 2, 3) suggest modifying the sys.path.insert
statement in the conf.py
file.
I have tried using:
sys.path.insert(0, os.path.abspath)
But the results are the same.
If I add the package's root path (sys.path.insert(0, 'c:debugsphinx')
, I get fewer errors from Sphinx, this time only related to thee subpackages core
and factory
:
WARNING: autodoc: failed to import module 'program' from module 'mypackage.core'; the following exception was raised:
No module named 'foo'
WARNING: autodoc: failed to import module 'basefactory' from module 'mypackage.factory'; the following exception was raised:
No module named 'core'
Ultimately, I can get this to produce the dox by inserting ALL of the paths in the conf.py
file:
sys.path.insert(0, 'c:debugsphinx')
sys.path.insert(0, 'c:debugsphinxmypackage')
sys.path.insert(0, 'c:debugsphinxmypackagecore')
sys.path.insert(0, 'c:debugsphinxmypackagefactory')
But it seems like I'm doing something wrong here. Is there a single path I can add to sys.path
that will let this work without import errors? Should I have to hardcode all of the paths to package/subpackages? Or if not, what am I doing wrong?
python python-3.x python-sphinx
1
You can continue to keep adding tosys.path
, but alternatively you could install the packages (i.e. usingsetuputils.setup
). That way your packages will reside where they can be imported by any module.
– Matt Messersmith
Nov 14 '18 at 16:55
the actual (non MCVE) code is managed as part of a VSTO solution and is necessarily contained in its project folders/etc. Will that matter?
– David Zemens
Nov 14 '18 at 16:58
What does VSTO stand for?
– Matt Messersmith
Nov 14 '18 at 16:59
VSTO = Visual Studio
– David Zemens
Nov 14 '18 at 17:00
1
And I meantsetuptools.setup
, notsetuputils
;). Mixed updistutils
andsetuptools
in the old brain...
– Matt Messersmith
Nov 14 '18 at 18:38
|
show 3 more comments
I have a project directory structured like so:
|--sphinx
|--mypackage
|--__init__.py
|--core
|--__init__.py
|--program.py
|--foo.py
|--factory
|--__init__.py
|--basefactory.py
First, I run the sphinx-apidoc
with the following paramters from command line:
c:Debugsphinx>sphinx-apidoc -o "C:DebugSphinx" "C:DebugSphinxmypackage" -f --full
This creates the folder structure, .bat and .rst files, etc., within the "output" directory. Good so far.
When I try to run the make html
, I get errors/warnings, indicating:
WARNING: autodoc: failed to import module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.foo' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.program' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory.basefactory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
Other similar questions (1, 2, 3) suggest modifying the sys.path.insert
statement in the conf.py
file.
I have tried using:
sys.path.insert(0, os.path.abspath)
But the results are the same.
If I add the package's root path (sys.path.insert(0, 'c:debugsphinx')
, I get fewer errors from Sphinx, this time only related to thee subpackages core
and factory
:
WARNING: autodoc: failed to import module 'program' from module 'mypackage.core'; the following exception was raised:
No module named 'foo'
WARNING: autodoc: failed to import module 'basefactory' from module 'mypackage.factory'; the following exception was raised:
No module named 'core'
Ultimately, I can get this to produce the dox by inserting ALL of the paths in the conf.py
file:
sys.path.insert(0, 'c:debugsphinx')
sys.path.insert(0, 'c:debugsphinxmypackage')
sys.path.insert(0, 'c:debugsphinxmypackagecore')
sys.path.insert(0, 'c:debugsphinxmypackagefactory')
But it seems like I'm doing something wrong here. Is there a single path I can add to sys.path
that will let this work without import errors? Should I have to hardcode all of the paths to package/subpackages? Or if not, what am I doing wrong?
python python-3.x python-sphinx
I have a project directory structured like so:
|--sphinx
|--mypackage
|--__init__.py
|--core
|--__init__.py
|--program.py
|--foo.py
|--factory
|--__init__.py
|--basefactory.py
First, I run the sphinx-apidoc
with the following paramters from command line:
c:Debugsphinx>sphinx-apidoc -o "C:DebugSphinx" "C:DebugSphinxmypackage" -f --full
This creates the folder structure, .bat and .rst files, etc., within the "output" directory. Good so far.
When I try to run the make html
, I get errors/warnings, indicating:
WARNING: autodoc: failed to import module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.foo' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core.program' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'core' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory.basefactory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
WARNING: autodoc: failed to import module 'factory' from module 'mypackage'; the following exception was raised:
No module named 'mypackage'
Other similar questions (1, 2, 3) suggest modifying the sys.path.insert
statement in the conf.py
file.
I have tried using:
sys.path.insert(0, os.path.abspath)
But the results are the same.
If I add the package's root path (sys.path.insert(0, 'c:debugsphinx')
, I get fewer errors from Sphinx, this time only related to thee subpackages core
and factory
:
WARNING: autodoc: failed to import module 'program' from module 'mypackage.core'; the following exception was raised:
No module named 'foo'
WARNING: autodoc: failed to import module 'basefactory' from module 'mypackage.factory'; the following exception was raised:
No module named 'core'
Ultimately, I can get this to produce the dox by inserting ALL of the paths in the conf.py
file:
sys.path.insert(0, 'c:debugsphinx')
sys.path.insert(0, 'c:debugsphinxmypackage')
sys.path.insert(0, 'c:debugsphinxmypackagecore')
sys.path.insert(0, 'c:debugsphinxmypackagefactory')
But it seems like I'm doing something wrong here. Is there a single path I can add to sys.path
that will let this work without import errors? Should I have to hardcode all of the paths to package/subpackages? Or if not, what am I doing wrong?
python python-3.x python-sphinx
python python-3.x python-sphinx
asked Nov 14 '18 at 16:49
David ZemensDavid Zemens
44.7k953102
44.7k953102
1
You can continue to keep adding tosys.path
, but alternatively you could install the packages (i.e. usingsetuputils.setup
). That way your packages will reside where they can be imported by any module.
– Matt Messersmith
Nov 14 '18 at 16:55
the actual (non MCVE) code is managed as part of a VSTO solution and is necessarily contained in its project folders/etc. Will that matter?
– David Zemens
Nov 14 '18 at 16:58
What does VSTO stand for?
– Matt Messersmith
Nov 14 '18 at 16:59
VSTO = Visual Studio
– David Zemens
Nov 14 '18 at 17:00
1
And I meantsetuptools.setup
, notsetuputils
;). Mixed updistutils
andsetuptools
in the old brain...
– Matt Messersmith
Nov 14 '18 at 18:38
|
show 3 more comments
1
You can continue to keep adding tosys.path
, but alternatively you could install the packages (i.e. usingsetuputils.setup
). That way your packages will reside where they can be imported by any module.
– Matt Messersmith
Nov 14 '18 at 16:55
the actual (non MCVE) code is managed as part of a VSTO solution and is necessarily contained in its project folders/etc. Will that matter?
– David Zemens
Nov 14 '18 at 16:58
What does VSTO stand for?
– Matt Messersmith
Nov 14 '18 at 16:59
VSTO = Visual Studio
– David Zemens
Nov 14 '18 at 17:00
1
And I meantsetuptools.setup
, notsetuputils
;). Mixed updistutils
andsetuptools
in the old brain...
– Matt Messersmith
Nov 14 '18 at 18:38
1
1
You can continue to keep adding to
sys.path
, but alternatively you could install the packages (i.e. using setuputils.setup
). That way your packages will reside where they can be imported by any module.– Matt Messersmith
Nov 14 '18 at 16:55
You can continue to keep adding to
sys.path
, but alternatively you could install the packages (i.e. using setuputils.setup
). That way your packages will reside where they can be imported by any module.– Matt Messersmith
Nov 14 '18 at 16:55
the actual (non MCVE) code is managed as part of a VSTO solution and is necessarily contained in its project folders/etc. Will that matter?
– David Zemens
Nov 14 '18 at 16:58
the actual (non MCVE) code is managed as part of a VSTO solution and is necessarily contained in its project folders/etc. Will that matter?
– David Zemens
Nov 14 '18 at 16:58
What does VSTO stand for?
– Matt Messersmith
Nov 14 '18 at 16:59
What does VSTO stand for?
– Matt Messersmith
Nov 14 '18 at 16:59
VSTO = Visual Studio
– David Zemens
Nov 14 '18 at 17:00
VSTO = Visual Studio
– David Zemens
Nov 14 '18 at 17:00
1
1
And I meant
setuptools.setup
, not setuputils
;). Mixed up distutils
and setuptools
in the old brain...– Matt Messersmith
Nov 14 '18 at 18:38
And I meant
setuptools.setup
, not setuputils
;). Mixed up distutils
and setuptools
in the old brain...– Matt Messersmith
Nov 14 '18 at 18:38
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305120%2fsphinx-fails-to-import-subpackages%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305120%2fsphinx-fails-to-import-subpackages%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can continue to keep adding to
sys.path
, but alternatively you could install the packages (i.e. usingsetuputils.setup
). That way your packages will reside where they can be imported by any module.– Matt Messersmith
Nov 14 '18 at 16:55
the actual (non MCVE) code is managed as part of a VSTO solution and is necessarily contained in its project folders/etc. Will that matter?
– David Zemens
Nov 14 '18 at 16:58
What does VSTO stand for?
– Matt Messersmith
Nov 14 '18 at 16:59
VSTO = Visual Studio
– David Zemens
Nov 14 '18 at 17:00
1
And I meant
setuptools.setup
, notsetuputils
;). Mixed updistutils
andsetuptools
in the old brain...– Matt Messersmith
Nov 14 '18 at 18:38