make packages installed in virtualenv visibile to sphinx -


i using sphinx document software. , using virtualenv installation. packages installed in virtual environment, , sphinx not see them.

i have code in conf.py:

# if extensions (or modules document autodoc) in directory, # add these directories sys.path here. if directory relative # documentation root, use os.path.abspath make absolute, shown here. p = os.path.abspath('..') sys.path.insert(0, p) if 'virtual_env' in os.environ:     q = os.sep.join([os.environ['virtual_env'],                      'lib', 'python2.7', 'site-packages'])     sys.path.insert(0, q)     p = p + ":" + q  os.environ['pythonpath'] = p 

yet if make html, sort of warnings:

/home/mario/local/github/bauble/bauble.classic/doc/api.rst:358: warning: autodoc: failed import class u'tagitemgui' module u'bauble.plugins.tag'; following exception raised: traceback (most recent call last):   file "/usr/local/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 385, in import_object     __import__(self.modname)   file "/home/mario/local/github/bauble/bauble.classic/bauble/plugins/tag/__init__.py", line 30, in <module>     sqlalchemy import * importerror: no module named sqlalchemy 

my $virtual_env/lib/python2.7/site-packages contains sqlalchemy-1.0.4-py2.7-linux-x86_64.egg.

definitely related question sphinx autodoc dies on importerror of third party package, description of procedure chose follow in broken link.

the problem packages not directly included in virtualenv's site-packages dir, need specify full path able import package there. use following hack:

if 'virtual_env' in os.environ:     site_packages_glob = os.sep.join([         os.environ['virtual_env'],         'lib', 'python2.7', 'site-packages', 'projectname-*py2.7.egg'])     site_packages = glob.glob(site_packages_glob)[-1]     sys.path.insert(0, site_packages) 

where projectname name of python module import.

note error prone, when have multiple versions of module, far works me.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -