`_distutils_hack` fails if called anything but `get-pip.py`
See original GitHub issueDescription
Pip fails to install:
which python
# /usr/local/opt/python/libexec/bin/python
/usr/local/opt/python/libexec/bin/python --version
# Python 3.9.10
down https://bootstrap.pypa.io/get-pip.py --destination=/var/folders/wm/8g56ry4s47z_hbt0tgv0m5gr0000gn/T/tmp.vv6opZCN
# down is an internal command
python /var/folders/wm/8g56ry4s47z_hbt0tgv0m5gr0000gn/T/tmp.vv6opZCN --user
# fails and outputs the next code block
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py:17: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is in/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py:30File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/overrideFile "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py:17: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
warnings.warn(
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
File "/var/folders/wm/8g56ry4s47z_hbt0tgv0m5gr0000gn/T/tmp.vv6opZCN", line 27081, in <module>
main()
File "/var/folders/wm/8g56ry4s47z_hbt0tgv0m5gr0000gn/T/tmp.vv6opZCN", line 139, in main
bootstrap(tmpdir=tmpdir)
File "/var/folders/wm/8g56ry4s47z_hbt0tgv0m5gr0000gn/T/tmp.vv6opZCN", line 120, in bootstrap
args = determine_pip_install_arguments()
File "/var/folders/wm/8g56ry4s47z_hbt0tgv0m5gr0000gn/T/tmp.vv6opZCN", line 65, in determine_pip_install_arguments
import setuptools # noqa
File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 8, in <module>
import _distutils_hack.override # noqa: F401
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/override.py", line 1, in <module>
__import__('_distutils_hack').do_override()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 71, in do_override
ensure_local_distutils()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 59, in ensure_local_distutils
assert '_distutils' in core.__file__, core.__file__
AssertionError: /usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py
Expected behavior
it to work fine
pip version
latest
Python version
3.9.10
OS
21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64
How to Reproduce
this works fine:
brew install python
wget https://bootstrap.pypa.io/get-pip.py
chmod +x ./get-pip.py
python ./get-pip.py --user
this fails, which is common when say saving the installer to a randomly generated temp file:
brew install python
wget https://bootstrap.pypa.io/get-pip.py
mv ./get-pip.py ./any-other-filename.py
chmod +x ./any-other-filename.py
python ./any-other-filename.py --user
Output
Warning: python@3.9 3.9.10 is already installed and up-to-date.
To reinstall 3.9.10, run:
brew reinstall python@3.9
--2022-01-19 23:48:26-- https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.52.175, 2a04:4e42:d::175
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.52.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2159352 (2.1M) [text/x-python]
Saving to: ‘get-pip.py’
get-pip.py 100%[============================================================>] 2.06M 1.65MB/s in 1.2s
2022-01-19 23:48:28 (1.65 MB/s) - ‘get-pip.py’ saved [2159352/2159352]
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py:17: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
warnings.warn(
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")
Traceback (most recent call last):
File "/Users/balupton/./any-other-filename.py", line 27081, in <module>
main()
File "/Users/balupton/./any-other-filename.py", line 139, in main
bootstrap(tmpdir=tmpdir)
File "/Users/balupton/./any-other-filename.py", line 120, in bootstrap
args = determine_pip_install_arguments()
File "/Users/balupton/./any-other-filename.py", line 65, in determine_pip_install_arguments
import setuptools # noqa
File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 8, in <module>
import _distutils_hack.override # noqa: F401
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/override.py", line 1, in <module>
__import__('_distutils_hack').do_override()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 71, in do_override
ensure_local_distutils()
File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 59, in ensure_local_distutils
assert '_distutils' in core.__file__, core.__file__
AssertionError: /usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py
Code of Conduct
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
`_distutils_hack` fails if called anything but `get-pip.py` - GitHub
This is realistically an issue with setuptools' hack, so I've moved the issue over.
Read more >python _distutils_hack | The AI Search Engine You Control
It's used by setuptools to replace the stdlib distutils with setuptools' bundled distutils ... _distutils_hack fails if called anything but get-pip.py #3439.
Read more >python - ModuleNotFoundError: No module named 'distutils.util'
I had a 3.7 version of distutils, I copied it in the python3.8 distutils package and no more error. sudo cp -r /usr/lib/python3.7/distutils...
Read more >How to install python-distutils for old python versions
I already have python3-distutils and python3-distutils-extra installed but pip only works for python 3.8. How can I make pip work for installing ...
Read more >Using virtualenv, Installing with Pip, and Managing Packages
When the files are ready and unpacked, using the distutils module, you can install it by calling setup.py : Installation example of a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve moved your comment to a new issue because it’s a different case.
I see now that in https://github.com/pypa/get-pip/pull/140, the get-pip script was updated not to import setuptools, and that script was probably updated in get-pip.py in late January, so I suspect the root cause of this issue has been addressed.
If any one else encounters this issue and can reproduce it (preferably in a Docker image) using the latest get-pip, please let us know.