How to force Sphinx to use Python 3.x interpreter

后端 未结 9 880
遇见更好的自我
遇见更好的自我 2020-12-05 14:56

I try to create documentation for a project written with Python 3.x. Sphinx is the tool I want to use and, according to the official site, its last version 1.1.2 is

相关标签:
9条回答
  • 2020-12-05 15:16

    When I searched for an answer, this is the site that came up over and over. I'm thinking the answer is not easy to find because everyone else understands sphinx better than I can figure out. But if any is still searching for an answer, this is what eventually I ended up with:

    sudo apt-get update

    sudo apt-get install python3

    sudo apt-get install sqlite3

    sudo apt-get install idle3

    sudo apt-get install python3-pip

    sudo apt-get install python3-docutils

    sudo apt-get install python3-jinja2

    sudo apt-get install python3-pygments

    sudo pip3 install Sphinx

    The key was I was missing the fact that there was a pip3. I also update the system before adding a package as habit.

    0 讨论(0)
  • 2020-12-05 15:17

    I'm on Ubunut and had the same problem. I won't use Josh_P or Nicolas answer because..

    • I don't want to change my PYTHON path.
    • I don't want to uninstall python-sphinx because I need it with older Projects.

    So i fixed it with this little script called sphinx3-build:

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    """
    Same as /usr/bin/sphinx-build but with different
    interpreter
    """
    
    import sys
    
    if __name__ == '__main__':
        from sphinx import main, make_main
        if sys.argv[1:2] == ['-M']:
            sys.exit(make_main(sys.argv))
        else:
            sys.exit(main(sys.argv))
    

    It's the same as sphinx-build but with a different interpreter. In the Makefile I changed the following line:

    SPHINXBUILD   = sphinx3-build
    

    Now copy the file to the /usr/bin/ folder:

    sudo cp sphinx3-build /usr/bin/
    

    This worked for me. You could also use it locally for one project only by placing the script into the same folder as the Makefile and set SPHINXBUILD to ./sphinx3-build.

    0 讨论(0)
  • 2020-12-05 15:25

    I think Sphinx simply uses the "python" command as interpreter. But according to the Makefile, you can specify your own with the PYTHON option, when running make for installation.

    0 讨论(0)
提交回复
热议问题