実現したいこと
エラーをなくしたいです。
発生している問題・分からないこと
実効を押すと次のようなエラーが出てきます。
ModuleNotFoundError: No module named 'distutils'
エラーメッセージ
error
1ModuleNotFoundError: No module named 'distutils'
該当のソースコード
from
1#画像の前処理をする 2# import os 3import cv2 4import numpy as np 5import glob as glob 6from sklearn.model_selection import train_test_split 7from keras.utils import np_utils 8 9 10#フォルダをクラス名にする 11path = "./ALL/gazou/img/deep_learning" 12folders = os.listdir(path) 13 14#フォルダ名を抽出 15classes = [f for f in folders if os.path.isdir(os.path.join(path, f))] 16n_classes = len(classes) 17 18 19#画像とラベルの格納 20X = [] 21Y = [] 22 23 24#画像を読み込みリサイズする 25for label,class_name in enumerate(classes): 26 files = glob.glob(path + "/" + class_name + "/*.png") 27 for file in files: 28 img = cv2.imread(file) 29 img = cv2.resize(img,dsize=(224,224)) 30 X.append(img) 31 Y.append(label) 32 33#精度を上げるために正規化 34X = np.array(X) 35X = X.astype('float32') 36X /= 255.0 37 38#ラベルの変換 39 40Y = np.array(Y) 41Y = np_utils.to_categorical(Y,n_classes) 42Y[:5] 43 44#学習データとテストデータに分ける(テストデータ2割、学習データ8割) 45X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.2) 46#学習データ(8割) 47print(X_train.shape) 48#テストデータ(2割) 49print(X_test.shape) 50#学習データ(8割) 51print(Y_train.shape) 52#テストデータ(2割) 53print(Y_test.shape)
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
pip install setuptoolsと入力しましたが、エラーは改善されませんでした。
補足
特になし
使っている python は anaconda ですか?ならば、conda install setuptools のほうがいいかもしれません。
ModuleNotFoundError: No module named 'distutils' の前後で Traceback は出ていないのですか?
> 実効を押すと
これはなんの話ですか?
Python 3.12 なのではないですか?
https://docs.python.org/ja/3/whatsnew/3.12.html
Of note, the distutils package has been removed from the standard library.
3.12 に distutils は含まれていないのですが、setuptools をインストールすれば distutils を import できるようになります。(複雑な仕組みを使っていて、なんで使えるようになるのかはわかりにくいです)
質問者さんは 3.12 を使っているんだと思いますが、pip install setuptools をしても distutils が import できないんだとしたら、setuptools のインストールがちゃんとできていないのだろうと思われます。
