macを使っているのですが、python3がどうしてもインストールできません、、
brewを使ってのインストールを試しても、インストールされているという表示が出るだけで、だめです。
前は使えていたのですが、vscodeを使おうとあれこれいじっていたら使えなくなってしまいました
解決法を教えてください、、
追記
前はpythonコマンドだけで動いていたのですが、今はpython3コマンドでないと動きません、、
python3コマンドでも長いコードだと下の謎のエラーが発生します
shinya@shinyanoMacBook-Air Colab Notebooks % python3 probability.py
Traceback (most recent call last):
File "/Volumes/GoogleDrive/マイドライブ/Colab Notebooks/probability.py", line 1, in <module>
from nltk.stem import WordNetLemmatizer
File "/opt/homebrew/lib/python3.9/site-packages/nltk/init.py", line 133, in <module>
from nltk.text import *
File "/opt/homebrew/lib/python3.9/site-packages/nltk/text.py", line 30, in <module>
from nltk.tokenize import sent_tokenize
File "/opt/homebrew/lib/python3.9/site-packages/nltk/tokenize/init.py", line 66, in <module>
from nltk.tokenize.casual import TweetTokenizer, casual_tokenize
File "/opt/homebrew/lib/python3.9/site-packages/nltk/tokenize/casual.py", line 38, in <module>
import regex # https://github.com/nltk/nltk/issues/2409
File "/opt/homebrew/lib/python3.9/site-packages/regex/init.py", line 1, in <module>
from .regex import *
File "/opt/homebrew/lib/python3.9/site-packages/regex/regex.py", line 419, in <module>
import regex._regex_core as _regex_core
File "/opt/homebrew/lib/python3.9/site-packages/regex/_regex_core.py", line 21, in <module>
import regex._regex as _regex
ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so, 2): no suitable image found. Did find:
/opt/homebrew/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
/opt/homebrew/lib/python3.9/site-packages/regex/_regex.cpython-39-darwin.so: mach-o, but wrong architecture
python3
1from nltk.stem import WordNetLemmatizer 2lemmatizer=WordNetLemmatizer() 3qlist=["単語2047個"] 4ty=input("which type?") 5import os,pytesseract,enchant,nltk 6from PIL import Image 7counter1=0 8counter2=0 9os.chdir(f"/Volumes/GoogleDrive/マイドライブ/Colab Notebooks/{ty}") 10for im in os.listdir(".")[1:]: 11 img=Image.open(im) 12 text=pytesseract.image_to_string(img,lang="eng") 13 text=text.replace("\n","") 14 text=nltk.word_tokenize(text) 15 text=nltk.pos_tag(text) 16 for word,type in list(set(text)): 17 if type in ["JJ","JJR","JJS"]: 18 counter1+=1 19 if lemmatizer.lemmatize(word,pos="a") in qlist: 20 counter2+=1 21 else: 22 print(word+" leaked") 23 elif type in ["NN","NNS","NNP","NNPS"]: 24 counter1+=1 25 if lemmatizer.lemmatize(word,pos="n"): 26 counter2+=1 27 else: 28 print(word+" leaked") 29 elif type in ["RB","RBS","RBR"]: 30 counter1+=1 31 if lemmatizer.lemmatize(word,pos="r") in qlist: 32 counter2+=1 33 else: 34 print(word+" leaked") 35 elif type in ["VB","VBD","VBG","VBN","VBP","VBZ"]: 36 counter1+=1 37 if lemmatizer.lemmatize(word,pos="v") in qlist: 38 counter2+=1 39 else: 40 print(word+" leaked") 41print("system covers"+str(100*counter2/counter1)+"%")
回答1件
あなたの回答
tips
プレビュー