#1032283 python3-sphinx: sphinx-build ignores virtual env

#1032283#5
Date:
2023-03-02 22:21:06 UTC
From:
To:
Dear Maintainer,

I used to install tensorflow with pip, and sphinx-build had no trouble
building my documentation which includes `import tensorflow`.

Since we are not supposed to use pip directly anymore, I created a
virtual environment, with the option --system-site-packages since I only
want to add a few things not packaged in Debian, and installed
tensorflow in it. I now activate the environment, run sphinx-build,
and... it fails to find tensorflow.

The issue is that sphinx-build starts with #!/usr/bin/python3 , it does
not use the python3 symlink that the activation added at the beginning
of PATH, and thus does not look for packages in my active virtual
environment.

I have many possible workarounds:
* execute python3 -m sphinx.cmd.build
* execute python3 /usr/bin/sphinx-build
* export a PYTHONPATH pointing to the virtual environment
* install another copy of sphinx in the virtual environment
etc

but they essentially mean that the sphinx-build script shipped by Debian
is useless to me, I just use the first workaround instead.

The most natural change would be to use #!/usr/bin/env python3, but
Debian policy says not to do that. Is there a way this policy could be
relaxed when there is a good reason? Or is there another way to let
sphinx-build do the right thing with virtual environments? Or should I
resign myself?

#1032283#10
Date:
2023-03-03 10:23:18 UTC
From:
To:
Hi Marc!

As you noted, /usr/bin/python3 shebang is part of the Debian Python Policy:

https://www.debian.org/doc/packaging-manuals/python-policy/#interpreter-directive-shebang

https://www.debian.org/doc/packaging-manuals/python-policy/#interpreter-location

I would just install another copy of Sphinx in a virtualenv. This will also
help pip to make sure all packages are compatible with each other.

I don't think your use case deserves changing the policy, but it's better to
discuss it on debian-python, maybe there are other opinions.