Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'distutils' has no attribute 'version' : with setuptools 59.6.0 #69894

Closed
keskival opened this issue Dec 14, 2021 · 30 comments
Labels
module: ci Related to continuous integration module: dependency bug Problem is not caused by us, but caused by an upstream library we use module: tensorboard triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@keskival
Copy link

keskival commented Dec 14, 2021

🐛 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

keskival pushed a commit to keskival/pytorch that referenced this issue Dec 14, 2021
…ools, so migrated to using packaging.version.Version.
@keskival
Copy link
Author

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

@keskival
Copy link
Author

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.

@keskival
Copy link
Author

Apparently there's an alternative pull request for this same bug here: #69823

@malfet
Copy link
Contributor

malfet commented Dec 14, 2021

#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

@malfet malfet added module: ci Related to continuous integration module: dependency bug Problem is not caused by us, but caused by an upstream library we use module: tensorboard triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Dec 14, 2021
rb-determined-ai added a commit to rb-determined-ai/determined that referenced this issue Dec 14, 2021
setuptools 59.6.0 exposed a bug in pytorch, where pytorch is improperly
importing a particular submodule of distutils.  In old setuptools,
distutils.version was automatically imported, but in new setuptools, it
is not.  For details, see:

    pytorch/pytorch#69894

Since forcing users to upgrade pytorch is not feasible, we intervene by
enforcing that distutils.version is imported before we try to import the
problematic torch.utils.tensorboard submodule.  This workaround will not
help users who import torch.utils.tensorboard directly, but it will
protect users who only import torch.utils.tensorboard because of us.
rb-determined-ai added a commit to rb-determined-ai/determined that referenced this issue Dec 14, 2021
setuptools 59.6.0 exposed a bug in pytorch, where pytorch is improperly
importing a particular submodule of distutils.  In old setuptools,
distutils.version was automatically imported, but in new setuptools, it
is not.  For details, see:

    pytorch/pytorch#69894

Since forcing users to upgrade pytorch is not feasible, we intervene by
enforcing that distutils.version is imported before we try to import the
problematic torch.utils.tensorboard submodule.  This workaround will not
help users who import torch.utils.tensorboard directly, but it will
protect users who only import torch.utils.tensorboard because of us.
mawilson1234 added a commit to clay-lab/structural-alternations that referenced this issue Dec 14, 2021
@keskival
Copy link
Author

Since #69904 has been merged, this issue can be closed.

rb-determined-ai added a commit to determined-ai/determined that referenced this issue Dec 15, 2021
setuptools 59.6.0 exposed a bug in pytorch, where pytorch is improperly
importing a particular submodule of distutils.  In old setuptools,
distutils.version was automatically imported, but in new setuptools, it
is not.  For details, see:

    pytorch/pytorch#69894

Since forcing users to upgrade pytorch is not feasible, we intervene by
enforcing that distutils.version is imported before we try to import the
problematic torch.utils.tensorboard submodule.  This workaround will not
help users who import torch.utils.tensorboard directly, but it will
protect users who only import torch.utils.tensorboard because of us.
alistair-english added a commit to QUT-Motorsport/QUTMS_Driverless that referenced this issue Dec 30, 2021
LoicGrobol added a commit to LoicGrobol/zeldarose that referenced this issue Jan 19, 2022
See <pytorch/pytorch#69894> for why, this should
be reverted as soon as this
PR lands in a pytorch release.
@lucasjinreal
Copy link

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'
>>>

@manbehindthemadness
Copy link

I can confirm that this is still a problem, I am experiencing the same issue.

@Mayankm96
Copy link

Managed to resolve this by:

pip install setuptools==59.5.0

@dustindorroh
Copy link

Managed to resolve this by:

pip install setuptools==59.5.0

Worked for me!

haouarihk added a commit to haouarihk/image-to-latex that referenced this issue Sep 11, 2022
`AttributeError: module 'distutils' has no attribute 'version'`

solved by this comment
pytorch/pytorch#69894 (comment)
@nhm-7
Copy link

nhm-7 commented Oct 2, 2022

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

@YuanYuan98
Copy link

It works for me, thx!

@Tiehhsin
Copy link

Managed to resolve this by:

pip install setuptools==59.5.0

Thank you so much!

@roachsinai
Copy link

So can't use the latest setuptools?

@xingbod
Copy link

xingbod commented Aug 3, 2023

pip install setuptools==59.5.0

works for me

@hhho0321
Copy link

Managed to resolve this by:设法通过以下方式解决此问题:

pip install setuptools==59.5.0

works for me, thanks!

@rayarit
Copy link

rayarit commented Feb 1, 2024

Managed to resolve this by:

pip install setuptools==59.5.0

Wow Thanks !!! @Mayankm96

@mnayebare
Copy link

pip install setuptools==59.5.0
worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: ci Related to continuous integration module: dependency bug Problem is not caused by us, but caused by an upstream library we use module: tensorboard triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.