AttributeError: module 'distutils' has no attribute 'version' : with setuptools 59.6.0
keskival opened this issue ยท 30 comments
๐ Describe the bug
# python3 -m pip install --upgrade setuptools torch tensorboard`
# python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torch.utils.tensorboard import SummaryWriter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/torch/utils/tensorboard/__init__.py", line 4, in <module>
LooseVersion = distutils.version.LooseVersion
AttributeError: module 'distutils' has no attribute 'version'
Versions
Collecting environment information...
PyTorch version: 1.10.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31
Python version: 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0] (64-bit runtime)
Python platform: Linux-5.4.0-88-generic-x86_64-with-glibc2.29
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Versions of relevant libraries:
[pip3] numpy==1.21.4
[pip3] torch==1.10.0
[conda] Could not collect
cc @seemethere @malfet @pytorch/pytorch-dev-infra
As per PEP-632 migration advice, distutils.version should migrate to using packaging.version instead:
https://www.python.org/dev/peps/pep-0632/#migration-advice
distutils.version
is also still used in several other places in testing tools and build utilities:
# find . -name "*.py" | xargs grep distutils\.version
./test/run_test.py: if distutils.version.LooseVersion(torch.version.cuda) >= "11.5":
./test/test_sparse.py:from distutils.version import LooseVersion
./test/test_spectral_ops.py:LooseVersion = distutils.version.LooseVersion
./torch/testing/_internal/common_methods_invocations.py: active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
./torch/testing/_internal/common_methods_invocations.py: active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
./torch/testing/_internal/common_methods_invocations.py: active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
./torch/testing/_internal/common_cuda.py:CUDA11OrLater = torch.version.cuda and distutils.version.LooseVersion(torch.version.cuda) >= "11.0"
./tools/setup_helpers/cmake.py: if cmake3 is not None and CMake._get_version(cmake3) >= distutils.version.LooseVersion("3.10.0"):
./tools/setup_helpers/cmake.py: elif cmake is not None and CMake._get_version(cmake) >= distutils.version.LooseVersion("3.10.0"):
./tools/setup_helpers/cmake.py: return distutils.version.LooseVersion(line.strip().split(' ')[2])
These are outside the scope of the pull request, which only fixes the immediate problem of inability to import TensorBoard.
#69904 should fix the immediate fallback of setuptools update.
As I've already mentioned in #69823 it would be good to have a more detailed comparison of packaging.Version
vs distuitls.version.LooseVersion
(as former more closely resembles distutils.version.StrictVersion
, isn't it?)
Also, version
is not removed from setuptool, it simply no-longer accidentally re-imported. Proper way to import it always been from distutils.version import LooseVersion
, not sure what started from setuptools import distutils; distuils.version.LooseVersion
anti-pattern
Still got error on torch1.110.2
/Users/xx/miniforge3/lib/python3.9/site-packages/torch/utils/tensorboard/__init__.py", line 4, in <module>
LooseVersion = distutils.version.LooseVersion
AttributeError: module 'distutils' has no attribute 'version'
(base) jMBP ~/d/c/a/b/GPT2-chitchat> python 1 master!
Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:24:02)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
t>>> torch.__version__
'1.10.2'
>>>
I can confirm that this is still a problem, I am experiencing the same issue.
Managed to resolve this by:
pip install setuptools==59.5.0
Managed to resolve this by:
pip install setuptools==59.5.0
Worked for me!
Same Issue with me
File "/opt/conda/lib/python3.7/site-packages/torch/utils/tensorboard/__init__.py", line 4, in <module>
LooseVersion = distutils.version.LooseVersion
AttributeError: module 'distutils' has no attribute 'version'
Python 3.7.10 (default, Feb 26 2021, 18:47:35)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.9.0'
>>>
Managed to resolve this by:
pip install setuptools==59.5.0
I followed Mayankm96's solution. It worked but I have no idea what's going on.
I could run tensorboard few days ago, but I met this error today.
I had the same problem as yktangac. What caused it?
Same problem here, resolved by downgrading setuptools from 60.9.2 to 59.5.0.
Managed to resolve this by:
pip install setuptools==59.5.0
I followed Mayankm96's solution. It worked but I have no idea what's going on. I could run tensorboard few days ago, but I met this error today.
Used this solution a while ago, and it appears this issue still exists, any future plans to fix this?
Managed to resolve this by:
pip install setuptools==59.5.0
works for me
Managed to resolve this by:
pip install setuptools==59.5.0
Thanks a lot! It works!!
Managed to resolve this by:
pip install setuptools==59.5.0
works for me!
Managed to resolve this by:
pip install setuptools==59.5.0
works for me too! Thanks a lot!
Managed to resolve this by:
pip install setuptools==59.5.0
Works for me, thank you so much
Managed to resolve this by:
pip install setuptools==59.5.0
it works for me, thx.
And my env:
cuda 11.4
torch 1.9.0
python 3.8.12
pip install setuptools==59.5.0
works for me
Users with pyenv and poetry will not work even with setuptools = "==59.5.0"
in pyproject.toml
. I am able to resolve with below command.
pyenv local 3.8.6
poetry env use $(pyenv which python)
poetry run pip install -U pip 'setuptools==59.5.0'
poetry install
Managed to resolve this by:
pip install setuptools==59.5.0
It works for me, thx!
My env (miniconda):
python 3.9
torch==1.9.1+cu111
torchvision==0.10.1+cu111
torchaudio==0.9.1
setuptools 59.5.0 added to my requirements.txt file:
scipy==1.8.0
numpy==1.22.3
pillow==9.1.0
transformers==4.12.3
matplotlib==3.5.1
spacy==3.2.2
stanza==1.2.3
spacy_stanza==1.0.0
textacy==0.11.0
pytorch-lightning==1.5.2
colorama==0.4.4
fairscale==0.4.3
setuptools==59.5.0
It works for me, thx!
Managed to resolve this by:
pip install setuptools==59.5.0
Thank you so much!
So can't use the latest setuptools?
pip install setuptools==59.5.0
works for me
Managed to resolve this by:่ฎพๆณ้่ฟไปฅไธๆนๅผ่งฃๅณๆญค้ฎ้ข๏ผ
pip install setuptools==59.5.0
works for me, thanks!
Managed to resolve this by:
pip install setuptools==59.5.0
Wow Thanks !!! @Mayankm96
pip install setuptools==59.5.0
worked for me