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

No module named 'distutils' on Python 3.12 #732

Closed
SyberiaK opened this issue Jan 31, 2024 · 21 comments
Closed

No module named 'distutils' on Python 3.12 #732

SyberiaK opened this issue Jan 31, 2024 · 21 comments
Assignees

Comments

@SyberiaK
Copy link

Steps to reproduce

  1. Install Python 3.12
  2. Install speech_recognition and pyaudio with pip (pip install SpeechRecognition and pip install pyaudio)
  3. Create a Python script with this code:
import speech_recognition as sr

mic = sr.Microphone()
print('hello')
  1. Launch the script.

Expected behaviour

hello printed in the console

Actual behaviour

Because distutils was removed in Python 3.12, we get ModuleNotFoundError: module named 'distutils'

System information

My Python version is 3.12.

@sapozhkov
Copy link

try
pip install setuptools

found on https://stackoverflow.com/questions/77931666/modulenotfounderror-no-module-named-distutils-how-to-solve-this-in-macos

@Paulprojects8711
Copy link

try pip install setuptools

found on https://stackoverflow.com/questions/77931666/modulenotfounderror-no-module-named-distutils-how-to-solve-this-in-macos

i had the same issue and that actually fixed it thank you

@ftnext
Copy link
Collaborator

ftnext commented Mar 17, 2024

Thank you for reporting this issue, finding a solution, trying and sharing a result.

ref: https://docs.python.org/3/whatsnew/3.12.html#summary-release-highlights

gh-95299: Do not pre-install setuptools in virtual environments created with venv. This means that distutils, setuptools, pkg_resources, and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

I wonder adding pip install setuptools to README.

@ftnext ftnext self-assigned this Mar 17, 2024
@tphollis
Copy link

I'm trying to use the pip install setuptools but I still get the error "ModuleNotFoundError: No module named 'distutils'". Actually, any time I try to use a pip command, that's the result. any ideas on how to get around this? I'm running on Ubuntu if that helps

@donkrasnov
Copy link

The same for me. I'm trying to do import undetected_chromedriver as uc but get an ModuleNotFoundError: No module named 'distutils'. I did pip install setuptools and get Requirement already satisfied:.... What I did wrong?

@zahra566
Copy link

The same for me. I'm trying to do import undetected_chromedriver as uc but get an ModuleNotFoundError: No module named 'distutils'. I did pip install setuptools and get Requirement already satisfied:.... What I did wrong?

I had the same problem while using tensorflow, I added this:
import setuptools.dist

@marcorussi
Copy link

Same problem, pip install setuptools is not enough.

@rafa-mblm
Copy link

For MAC and Homebrew use brew install python-setuptools

@jasonlytehouse
Copy link

jasonlytehouse commented Jun 23, 2024

Try pip install --upgrade setuptools
Got it from here

@shubhi
Copy link

shubhi commented Jul 29, 2024

there is a '_disutils_hacks' file in the environmental site-packages, which will tell you to import setuptools before disutils is being used anywhere, which will definitely solve the issue.

@RubTalha
Copy link

RubTalha commented Aug 1, 2024

https://stackoverflow.com/a/76691103/13086128

@mxcxpx
Copy link

mxcxpx commented Aug 14, 2024

hello - now with new Linux mint22 or ubuntu24 none of this will help .. and iam lost

pip install --upgrade setuptools
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

@ltspicer
Copy link

hello - now with new Linux mint22 or ubuntu24 none of this will help .. and iam lost

pip install --upgrade setuptools error: externally-managed-environment

× This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.

How to Fix the pip externally-managed-environment error on Linux:

https://www.makeuseof.com/fix-pip-error-externally-managed-environment-linux/

@Naateri
Copy link

Naateri commented Sep 5, 2024

The same for me. I'm trying to do import undetected_chromedriver as uc but get an ModuleNotFoundError: No module named 'distutils'. I did pip install setuptools and get Requirement already satisfied:.... What I did wrong?

I had the same problem while using tensorflow, I added this: import setuptools.dist

This worked like a charm. Tried upgrading and reinstalling setuptools, but this did it.

@bendy05
Copy link

bendy05 commented Oct 16, 2024

Restart the kernel if it doesn't work right away

@sincerexie
Copy link

For MAC and Homebrew use brew install python-setuptools

Thank you very much! Your solution is fantastic!

@ftnext ftnext mentioned this issue Oct 19, 2024
1 task
@ftnext
Copy link
Collaborator

ftnext commented Oct 20, 2024

Thank you all!
I've just released SpeechRecognition 3.11.0, distutils removed version.

@ftnext ftnext closed this as completed Oct 20, 2024
@figredos
Copy link

figredos commented Oct 30, 2024

For MAC and Homebrew use brew install python-setuptools

This is what solved my problem.

Working from a MAC and with python 3.12

Thank you so much

@Kenhooo
Copy link

Kenhooo commented Nov 6, 2024

@rehmatworks
Copy link

rehmatworks commented Nov 20, 2024

On MacOS, I encountered this error with the main pip and pip3 commands in the activated Python 3.12 virtual environment. Maybe that's relevant here too. I wasn't able to execute pip install at all. What fixed the issue for me is to upgrade the pip version:

# Created virtualenv
virtualenv -p python3.12 venv

# Activated it
source venv/bin/activate

# Downloaded get-pip.py
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

# And upgraded pip version
python get-pip.py

@tlorens
Copy link

tlorens commented Dec 20, 2024

For MAC and Homebrew use brew install python-setuptools

This is what solved my problem.

Working from a MAC and with python 3.12

Thank you so much

This worked for me. It's the proper and clean way. Apple M3 Pro / Sequoia 15.1.1

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests