Skip to content

Remove distutils#57040

Closed
driazati wants to merge 5 commits intomasterfrom
ci-all/test_distutils
Closed

Remove distutils#57040
driazati wants to merge 5 commits intomasterfrom
ci-all/test_distutils

Conversation

@driazati
Copy link
Copy Markdown
Contributor

@driazati driazati commented Apr 27, 2021

distutils is on its way out and will be deprecated-on-import for Python 3.10+ and removed in Python 3.12 (see PEP 632). There's no reason for us to keep it around since all the functionality we want from it can be found in setuptools / sysconfig.

Fixes #56527

Differential Revision: D28051356

[distutils](https://docs.python.org/3/library/distutils.html) is on its
way out and will be deprecated-on-import for Python 3.10+ and removed in
Python 3.12 (see [PEP 632](https://www.python.org/dev/peps/pep-0632/)).
There's no reason for us to keep it around since all the functionality
we want from it can be found in `setuptools`.t s
@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Apr 27, 2021

💊 CI failures summary and remediations

As of commit 82bcc49 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-scanned failure(s)

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@driazati driazati mentioned this pull request Apr 28, 2021
@driazati driazati changed the title ci all/test distutils Remove distutils Apr 28, 2021
print(sysconfig.get_python_lib(prefix=''))
import sysconfig
relative_site_packages = sysconfig.get_path('purelib').replace(sysconfig.get_path('data'), '').lstrip(os.path.sep)
print(relative_site_packages)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the heck is this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysconfig hardcodes these paths with templates, but distutils.sysconfig doesn't and lets you supply your own prefix (i.e. base in the link), so here we end up having to remove the base (and its trailing slash) prefix manually.

>>> from distutils import sysconfig

>>> sysconfig.get_python_lib()
'/home/davidriazati/local/miniconda3/envs/pytorch/lib/python3.9/site-packages'

>>> sysconfig.get_python_lib(prefix='')
'lib/python3.9/site-packages'
>>> import sysconfig

>>> sysconfig.get_path('purelib')
'/home/davidriazati/local/miniconda3/envs/pytorch/lib/python3.9/site-packages'

>>> sysconfig.get_path('data') 
'/home/davidriazati/local/miniconda3/envs/pytorch'

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Apr 28, 2021

For the most part things look simpler. But two spots look very suspect, both in caffe2/CMakeLists.txt, where the logic has gotten substantially longer. What's going on?

@driazati
Copy link
Copy Markdown
Contributor Author

See comment about the first weird thing, for the second it's only to work around that bug linked in the comments (the fix for which is in 3.8+ but isn't getting backported any further than that). There are definitely some un-addressed gaps in the deprecation PEP but it's accepted so 🤷

Copy link
Copy Markdown
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okey dokey

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@driazati merged this pull request in 4b96fc0.

@xkszltl
Copy link
Copy Markdown
Contributor

xkszltl commented May 1, 2021

I noticed on Ubuntu 18.04, caffe2 has been moved from /usr/local/lib/python3/dist-packages to /usr/local/lib/python3.6/site-packages recently, with dist->site and 3->3.6.
I love the move because it's finally consistent with other distros, but not sure which commit introduced the behavior, to check whether it is a reliable change.
So far I only found this PR to be suspicious.
IIRC Ubuntu has some special patches for distutils to create things like dist-packages vs. site-packages.
If so, could you have confirm?

Thanks in advance.

@xkszltl
Copy link
Copy Markdown
Contributor

xkszltl commented May 1, 2021

I can confirm the change is related to this PR:

# lsb_release -d
Description:    Ubuntu 18.04.5 LTS
# python3 -c 'import sysconfig, distutils.sysconfig; print(sysconfig.get_path("purelib"), distutils.sysconfig.get_python_lib())'
/usr/lib/python3.6/site-packages /usr/lib/python3/dist-packages

Another thing I want to mention is, seems by default Debian python only load from dist-packages:

# python3 -c 'import sys; print(sys.path)'
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']

xkszltl added a commit to xkszltl/Roaster that referenced this pull request May 1, 2021
@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented May 3, 2021

@xkszltl Thanks for the diagnosis. Do you think there's anything we need to do?

@xkszltl
Copy link
Copy Markdown
Contributor

xkszltl commented May 3, 2021

Do you think there's anything we need to do?

  1. Confirm if this is an intentional change (so that it won't be "fixed"). If so I can start depending on the new result.
  2. Double check if Debian/Ubuntu can pick it up from site-packages without extra PYTHONPATH.

@driazati
Copy link
Copy Markdown
Contributor Author

driazati commented May 3, 2021

This shouldn't affect wheel installs since those are all relative from the .whl file zip structure, but I think it would mess up builds from source on Debian/Ubuntu that don't use conda (i.e. just using the bare system Python). I'm not sure if we even support this (@malfet ?) and it wasn't caught by the CI/my local development since the Python versions there come from CentOS as described in PEP 513.

It seems to be an unresolved issue, see pypa/distutils#17, looks like setuptools reverted their move away from distutils due to that issue. The SETUPTOOLS_USE_DISTUTILS fix also may not here since we manually specify the install location in cmake.

So if we require conda then this isn't a problem (the language in the README seems to only strongly suggest it, but then assumes it's there), but if we don't then the total removal of distutils might be premature until setuptools comes up with a better fix.

@xkszltl
Copy link
Copy Markdown
Contributor

xkszltl commented May 4, 2021

@driazati
If for backward compatibility you may simply symlink between python3/dist-packages/torch and python3.x/site-packages/torch.

We've been using cmake+pip build for a long while without issue, so I believe that's supported in reality, no matter official or not.
Requiring conda would be a bad idea, because its own environment won't be compatible with other things on system.
IMHO conda is kind of "evil", in the sense of env contamination.

krshrimali pushed a commit to krshrimali/pytorch that referenced this pull request May 19, 2021
Summary:
[distutils](https://docs.python.org/3/library/distutils.html) is on its way out and will be deprecated-on-import for Python 3.10+ and removed in Python 3.12 (see [PEP 632](https://www.python.org/dev/peps/pep-0632/)). There's no reason for us to keep it around since all the functionality we want from it can be found in `setuptools` / `sysconfig`. `setuptools` includes a copy of most of `distutils` (which is fine to use according to the PEP), that it uses under the hood, so this PR also uses that in some places.

Fixes pytorch#56527
Pull Request resolved: pytorch#57040

Pulled By: driazati

Reviewed By: nikithamalgifb

Differential Revision: D28051356

fbshipit-source-id: 1ca312219032540e755593e50da0c9e23c62d720
malfet added a commit to malfet/pytorch that referenced this pull request Dec 14, 2021
This fixes regression introduced by pytorch#57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```
facebook-github-bot pushed a commit that referenced this pull request Dec 14, 2021
Summary:
This fixes regression introduced by #57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: #69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
alanwaketan pushed a commit that referenced this pull request Dec 14, 2021
Summary:
This fixes regression introduced by #57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: #69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
jeffdaily pushed a commit to ROCm/pytorch that referenced this pull request Apr 13, 2022
Summary:
This fixes regression introduced by pytorch#57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: pytorch#69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
jeffdaily added a commit to ROCm/pytorch that referenced this pull request Apr 14, 2022
Properly import LooseVersion (pytorch#69904)

Summary:
This fixes regression introduced by pytorch#57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: pytorch#69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
pruthvistony pushed a commit to ROCm/pytorch that referenced this pull request Apr 21, 2022
Properly import LooseVersion (pytorch#69904)

Summary:
This fixes regression introduced by pytorch#57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: pytorch#69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
jithunnair-amd pushed a commit to jithunnair-amd/pytorch that referenced this pull request Sep 20, 2022
Properly import LooseVersion (pytorch#69904)

Summary:
This fixes regression introduced by pytorch#57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: pytorch#69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Sep 28, 2022
Properly import LooseVersion (pytorch#69904)

Summary:
This fixes regression introduced by pytorch#57040

Somehow importing `distutils` from `setuptool` caused import of
`distutils.versions`, which is not a documented dependency and got
change with the release of
[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
We should not rely on that, as
`import distutils` never re-imports `distutils.version`, which one can
see by observing
https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
or by running:
```
% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
```

Pull Request resolved: pytorch#69904

Reviewed By: albanD, atalman, janeyx99

Differential Revision: D33094453

Pulled By: malfet

fbshipit-source-id: aaf1adb7c6f293c4e376ccff21c64cd6ba625e97
@xkszltl
Copy link
Copy Markdown
Contributor

xkszltl commented Dec 2, 2022

On Ubuntu 22.04, saw it moved to /usr/local/lib/python3.10/dist-packages recently.

@github-actions github-actions bot deleted the ci-all/test_distutils branch February 11, 2024 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove distutils

4 participants