Open david-cortes opened 5 years ago
I can repro a similar problem with the following minimal setup: pyproject.toml:
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[project]
name = "mod"
version = "42"
with an empty mod.py next to it.
Running pip wheel -v .
or pip install -ve .
for example succeeds, but prints out large amounts of tracebacks like
--- Logging error ---
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\envs\myenv\lib\logging\__init__.py", line 1103, in emit
stream.write(msg + self.terminator)
ValueError: underlying buffer has been detached
Call stack:
<elided>
Message: 'removing build\\bdist.win-amd64\\wheel'
Arguments: ()
Hi @anntzer, I am afraid I cannot reproduce the error in the Windows machine I have available (I am using Windows 10, PowerShell 5.1.19041.1682, Python 3.9.13):
mkdir test-stdout-detached
cd test-stdout-detached
# Write the given pyproject.toml example to a file using UTF-8/unix line ending encodings
echo "" > mod.py
python -m pip wheel .
# ...
# Successfully built mod
# (file mod-42-py3-none-any.whl is created successfully)
This is probably related to a specific setup you have in your environment.
I recommend trying again using an isolated virtual environment (python -m venv
, not the conda ones).
I have repro'd again this with a clean, entirely new, python.org python 3.11 install in Windows 10 Pro 21H2, whether outside of any venv or inside a clean, entirely new venv, whether in cmd.exe or in PowerShell 7.3.
I have repro'd again this with a clean, entirely new, python.org python 3.11 install in Windows 10 Pro 21H2, whether outside of any venv or inside a clean, entirely new venv, whether in cmd.exe or in PowerShell 7.3.
I still cannot reproduce it I am afraid 😅 Could you please share a windows docker container with the reproducer?
Sorry, setting up a Windows docker container is a bit beyond my expertise...
No problems @anntzer, thank you anyway for having attempted to propose a reproducer.
I wrote a test using Dockerfile
(see bellow). Everything goes well and I cannot observe the faulty behaviour described in this issue.
To keep investigating, it would be necessary that a member of the community that is experiencing this problem provide a minimal reproducer that can be executed in an isolated environment (ideally via a windows container, as shown below).
If there is no reproducer available, I think it would be safe to say that this problem is more likely to be related on how an specific environment is setup (e.g. how Python is being compiled/installed) than to setuptools itself (and therefore we can close this issue).
rm -R isolated-test-in-container
mkdir isolated-test-in-container
cd isolated-test-in-container
new-item pyproject.toml
new-item Dockerfile
@"
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[project]
name = "mod"
version = "42"
"@ | add-content -Path pyproject.toml
@"
FROM python:3.11-windowsservercore-1809
RUN mkdir C:/pkg
WORKDIR C:/pkg
COPY pyproject.toml .
RUN python -m pip install -U pip setuptools wheel
CMD pip wheel -v .
"@ | add-content -Path Dockerfile
docker build -t isolated-test .
docker run --rm -it isolated-test
Please also note that I tried to run in a container the original suggestion (pip install nonnegcg
- https://github.com/pypa/setuptools/issues/1631#issue-397021655) and that fails, but because of compilation problems, not because of underlying buffer has been detached
. Instead, Python/pip/setuptools seem to be handling the stdout quite well:
rm -R isolated-test-in-container
mkdir isolated-test-in-container
cd isolated-test-in-container
new-item Dockerfile
@"
FROM python:3.11-windowsservercore-1809
RUN python -m pip install -U pip setuptools wheel numpy findblas Cython mkl-devel
CMD python -m pip install nonnegcg --no-build-isolation --no-use-pep517
"@ | add-content -Path Dockerfile
docker build -t isolated-test .
docker run --rm -it isolated-test
Hi @abravalheri,
I have the same errors by executing the @anntzer's simple steps:
The file mod-42-py3-none-any.whl is generated but there are these ugly error messages in the standard output like:
--- Logging error ---
Traceback (most recent call last):
File "C:\dev\Python311\Lib\logging\__init__.py", line 1113, in emit
stream.write(msg + self.terminator)
ValueError: underlying buffer has been detached
Call stack:
File "C:\dev\Python311\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 351, in <module>
main()
File "C:\dev\Python311\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\dev\Python311\Lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 249, in build_wheel
return _build_backend().build_wheel(wheel_directory, config_settings,
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\build_meta.py", line 412, in build_wheel
return self._build_with_temp_dir(['bdist_wheel'], '.whl',
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\build_meta.py", line 397, in _build_with_temp_dir
self.run_setup()
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
exec(code, locals())
File "<string>", line 1, in <module>
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\__init__.py", line 87, in setup
return distutils.core.setup(**attrs)
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
return run_commands(dist)
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
dist.run_commands()
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 968, in run_commands
self.run_command(cmd)
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\dist.py", line 1217, in run_command
super().run_command(command)
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 987, in run_command
cmd_obj.run()
File "C:\Users\daniel\AppData\Local\Temp\pip-build-env-pg7a2f7d\normal\Lib\site-packages\wheel\bdist_wheel.py", line 399, in run
log.info(f"removing {self.bdist_dir}")
Message: 'removing build\\bdist.win-amd64\\wheel'
Arguments: ()
It is not linked to a python version as I have the same with python 3.9 and 3.10. I suspect something wrong in the logging of setuptools arround the following line? https://github.com/pypa/setuptools/blob/a0e8e53cecc238e3bce2247308fe7dd94114ef35/setuptools/dist.py#L1202-L1210
If it can help, here is the full traces: traces.log
Hi,
To be able to debug the use case, I have changed the steps as follow:
pyproject.toml:
[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"
[project]
name = "mod"
version = "42"
setup.py:
from setuptools import setup
setup()
The standard output is fixed if I change the following in setuptools/dist.py: from:
sys.stdout = io.TextIOWrapper(
sys.stdout.detach(), 'utf-8', errors, newline, line_buffering
)
try:
return _Distribution.handle_display_options(self, option_order)
finally:
sys.stdout = io.TextIOWrapper(
sys.stdout.detach(), encoding, errors, newline, line_buffering
)
to:
sys.stdout.reconfigure(encoding='utf-8')
try:
return _Distribution.handle_display_options(self, option_order)
finally:
sys.stdout.reconfigure(encoding=encoding)
I will use this tweak. However, the function reconfigure() is available only from python 3.7. But that's fine for me as I'm using python 3.10.
From pypi website, the latest setuptools requires at least python 3.7. So, perhaps, this kind of tweak can be committed to the repo.
Hi @dlaugt, thank you very much for investigating this.
What is puzzling me is that I could not reproduce this in my Windows machine or in an isolated Windows container (I admit that I am probably not using the exact version of Windows you guys are using because of licenses/availability).
Probably there is some information missing to create a reproducer. I wonder which console/terminal program you guys are using and which encoding it is configured to use... Maybe that is the missing piece?
If you have tested the proposed patch and it works for you, would you like to submit a PR? Ideally we would like to have regression tests associated, but that might be tricky in this situation... Maybe just the fact that it does not fail the existing test suite is enough... (But please feel free to suggest a test suite if you are feeling creative). Once the PR is submitted, I will probably ask for the other maintainers to review.
I'm running this from a command prompt window (%windir%\system32\cmd.exe). The encoding is utf-8
:
python -c "import sys; print(sys.stdout.encoding)"
utf-8
However, when I launch python setup.py bdist_wheel
, it goes to setuptools.Distribution.handle_display_options()
. Inside this function, the encoding is cp1252
...
I will create a PR.
I guess I understood why you cannot reproduce it... In fact, I was redirecting the standard & error output into a file.
From cmd.exe, it worked fine when I run the following:
python -c "import sys; print(sys.stdout.encoding)"
utf-8
python setup.py bdist_wheel
From cmd.exe, it didn't work fine when I run the following:
python -c "import sys; print(sys.stdout.encoding)" > traces.log 2>&1
cp1252
python setup.py bdist_wheel > traces.log 2>&1
However, the command bdist_wheel
should work also when you redirect the standard & error output into a file. So, the pull request is fixing the following use case:
python setup.py bdist_wheel > traces.log 2>&1
I’m not entirely sure what’s the problem here, but I have this package in PyPI: https://pypi.org/project/nonnegcg/
Whenever I try to install it Windows machines through
pip
orsetuptools
(e.g.pip install nonnegcg
), I get an error at the moment something tries to write to standard output (which is bound to happen during installation), bet itprint
,warning
, or something else, which crashes the installation:Installing it with
distutils
from the downloaded file does not result in any problems (python setup.py install
, modifyingsetup.py
to importsetup
fromdistutils
rather than fromsetuptoos
), and it install just fine frompip
andsetup.py
+setuptools
in linux, but not on windows.