質問編集履歴
1
プログラムの言語を表示
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,184 +12,184 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
```python
|
16
|
+
|
17
|
+
from watchdog.events import FileSystemEventHandler
|
18
|
+
|
19
|
+
from watchdog.observers import Observer
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
import os
|
24
|
+
|
25
|
+
import time
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
target_dir = "aaa.jpg"
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
class ChangeHandler(FileSystemEventHandler):
|
36
|
+
|
37
|
+
def on_created(self, event):
|
38
|
+
|
39
|
+
filepath = event.src_path
|
40
|
+
|
41
|
+
filename = os.path.basename(filepath)
|
42
|
+
|
43
|
+
print('%sができました' % filename)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def on_modified(self, event):
|
48
|
+
|
49
|
+
filepath = event.src_path
|
50
|
+
|
51
|
+
filename = os.path.basename(filepath)
|
52
|
+
|
53
|
+
print('%sを変更しました' % filename)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
def on_deleted(self, event):
|
58
|
+
|
59
|
+
filepath = event.src_path
|
60
|
+
|
61
|
+
filename = os.path.basename(filepath)
|
62
|
+
|
63
|
+
print('%sを削除しました' % filename)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
if __name__ in '__main__':
|
70
|
+
|
71
|
+
while 1:
|
72
|
+
|
73
|
+
event_handler = ChangeHandler()
|
74
|
+
|
75
|
+
observer = Observer()
|
76
|
+
|
77
|
+
observer.schedule(event_handler, target_dir, recursive=True)
|
78
|
+
|
79
|
+
observer.start()
|
80
|
+
|
81
|
+
try:
|
82
|
+
|
83
|
+
while True:
|
84
|
+
|
85
|
+
time.sleep(0.1)
|
86
|
+
|
87
|
+
except KeyboardInterrupt:
|
88
|
+
|
89
|
+
observer.stop()
|
90
|
+
|
91
|
+
observer.join()
|
92
|
+
|
15
93
|
```
|
16
94
|
|
95
|
+
**2 実行結果**
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```bash
|
100
|
+
|
101
|
+
/usr/local/bin/python3 /Users/AM/Desktop/aaa/image_process_Gray.py
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
The default interactive shell is now zsh.
|
106
|
+
|
107
|
+
To update your account to use zsh, please run `chsh -s /bin/zsh`.
|
108
|
+
|
109
|
+
For more details, please visit https://support.apple.com/kb/HT208050.
|
110
|
+
|
111
|
+
pcAM:aaa AM$ /usr/local/bin/python3 /Users/AM/Desktop/aaa/image_process_Gray.py
|
112
|
+
|
113
|
+
Traceback (most recent call last):
|
114
|
+
|
115
|
+
File "/Users/AM/Desktop/aaa/image_process_Gray.py", line 1, in <module>
|
116
|
+
|
17
|
-
from watchdog.events import FileSystemEventHandler
|
117
|
+
from watchdog.events import FileSystemEventHandler
|
18
|
-
|
19
|
-
|
118
|
+
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
import os
|
24
|
-
|
25
|
-
import time
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
target_dir = "aaa.jpg"
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
class ChangeHandler(FileSystemEventHandler):
|
36
|
-
|
37
|
-
def on_created(self, event):
|
38
|
-
|
39
|
-
filepath = event.src_path
|
40
|
-
|
41
|
-
filename = os.path.basename(filepath)
|
42
|
-
|
43
|
-
print('%sができました' % filename)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def on_modified(self, event):
|
48
|
-
|
49
|
-
filepath = event.src_path
|
50
|
-
|
51
|
-
filename = os.path.basename(filepath)
|
52
|
-
|
53
|
-
print('%sを変更しました' % filename)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
def on_deleted(self, event):
|
58
|
-
|
59
|
-
filepath = event.src_path
|
60
|
-
|
61
|
-
filename = os.path.basename(filepath)
|
62
|
-
|
63
|
-
print('%sを削除しました' % filename)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
119
|
+
ModuleNotFoundError: No module named 'watchdog'
|
70
|
-
|
71
|
-
|
120
|
+
|
72
|
-
|
73
|
-
event_handler = ChangeHandler()
|
74
|
-
|
75
|
-
observer = Observer()
|
76
|
-
|
77
|
-
observer.schedule(event_handler, target_dir, recursive=True)
|
78
|
-
|
79
|
-
observer.start()
|
80
|
-
|
81
|
-
try:
|
82
|
-
|
83
|
-
|
121
|
+
pcAM:aaa AM$
|
84
|
-
|
85
|
-
time.sleep(0.1)
|
86
|
-
|
87
|
-
except KeyboardInterrupt:
|
88
|
-
|
89
|
-
observer.stop()
|
90
|
-
|
91
|
-
observer.join()
|
92
122
|
|
93
123
|
```
|
94
124
|
|
125
|
+
|
126
|
+
|
95
|
-
**
|
127
|
+
**3 試してみたことについて**
|
128
|
+
|
129
|
+
パスが通ってないことが原因かと考えました.
|
130
|
+
|
131
|
+
文献[2]を見ると,Pythonがモジュールの検索の際に見ているパスのリストは
|
132
|
+
|
133
|
+
"sys.path"に格納されているとあったので,以下のようにして(文献[1]を参考にして),パスを追加しました.その後,プログラムを起動したのですが,同じく,ModuleNotFoundError: No module named 'watchdog'が出てしまい解決できませんでした.
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
```bash
|
138
|
+
|
139
|
+
pcAM:Web_Image AM$ pip install watchdog
|
140
|
+
|
141
|
+
Requirement already satisfied: watchdog in /Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages (0.10.4)
|
142
|
+
|
143
|
+
Requirement already satisfied: pathtools>=0.1.1 in /Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages (from watchdog) (0.1.2)
|
144
|
+
|
145
|
+
WARNING: You are using pip version 20.1.1; however, version 20.3 is available.
|
146
|
+
|
147
|
+
You should consider upgrading via the '/Users/AM/.pyenv/versions/3.8.5/bin/python3.8 -m pip install --upgrade pip' command.
|
148
|
+
|
149
|
+
pcAM:Web_Image AM$ python
|
150
|
+
|
151
|
+
Python 3.8.5 (default, Dec 3 2020, 15:56:00)
|
152
|
+
|
153
|
+
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
|
154
|
+
|
155
|
+
Type "help", "copyright", "credits" or "license" for more information.
|
156
|
+
|
157
|
+
>>> import sys, pprint
|
158
|
+
|
159
|
+
>>> pprint.pprint(sys.path)
|
160
|
+
|
161
|
+
['',
|
162
|
+
|
163
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python38.zip',
|
164
|
+
|
165
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8',
|
166
|
+
|
167
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/lib-dynload',
|
168
|
+
|
169
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages']
|
170
|
+
|
171
|
+
>>> sys.path.append('/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages')
|
172
|
+
|
173
|
+
>>> pprint.pprint(sys.path)
|
174
|
+
|
175
|
+
['',
|
176
|
+
|
177
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python38.zip',
|
178
|
+
|
179
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8',
|
180
|
+
|
181
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/lib-dynload',
|
182
|
+
|
183
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages',
|
184
|
+
|
185
|
+
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages']
|
186
|
+
|
187
|
+
>>> quit()
|
96
188
|
|
97
189
|
|
98
190
|
|
99
191
|
```
|
100
192
|
|
101
|
-
/usr/local/bin/python3 /Users/AM/Desktop/aaa/image_process_Gray.py
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
The default interactive shell is now zsh.
|
106
|
-
|
107
|
-
To update your account to use zsh, please run `chsh -s /bin/zsh`.
|
108
|
-
|
109
|
-
For more details, please visit https://support.apple.com/kb/HT208050.
|
110
|
-
|
111
|
-
pcAM:aaa AM$ /usr/local/bin/python3 /Users/AM/Desktop/aaa/image_process_Gray.py
|
112
|
-
|
113
|
-
Traceback (most recent call last):
|
114
|
-
|
115
|
-
File "/Users/AM/Desktop/aaa/image_process_Gray.py", line 1, in <module>
|
116
|
-
|
117
|
-
from watchdog.events import FileSystemEventHandler
|
118
|
-
|
119
|
-
ModuleNotFoundError: No module named 'watchdog'
|
120
|
-
|
121
|
-
pcAM:aaa AM$
|
122
|
-
|
123
|
-
```
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
**3 試してみたことについて**
|
128
|
-
|
129
|
-
パスが通ってないことが原因かと考えました.
|
130
|
-
|
131
|
-
文献[2]を見ると,Pythonがモジュールの検索の際に見ているパスのリストは
|
132
|
-
|
133
|
-
"sys.path"に格納されているとあったので,以下のようにして(文献[1]を参考にして),パスを追加しました.その後,プログラムを起動したのですが,同じく,ModuleNotFoundError: No module named 'watchdog'が出てしまい解決できませんでした.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
```
|
138
|
-
|
139
|
-
pcAM:Web_Image AM$ pip install watchdog
|
140
|
-
|
141
|
-
Requirement already satisfied: watchdog in /Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages (0.10.4)
|
142
|
-
|
143
|
-
Requirement already satisfied: pathtools>=0.1.1 in /Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages (from watchdog) (0.1.2)
|
144
|
-
|
145
|
-
WARNING: You are using pip version 20.1.1; however, version 20.3 is available.
|
146
|
-
|
147
|
-
You should consider upgrading via the '/Users/AM/.pyenv/versions/3.8.5/bin/python3.8 -m pip install --upgrade pip' command.
|
148
|
-
|
149
|
-
pcAM:Web_Image AM$ python
|
150
|
-
|
151
|
-
Python 3.8.5 (default, Dec 3 2020, 15:56:00)
|
152
|
-
|
153
|
-
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
|
154
|
-
|
155
|
-
Type "help", "copyright", "credits" or "license" for more information.
|
156
|
-
|
157
|
-
>>> import sys, pprint
|
158
|
-
|
159
|
-
>>> pprint.pprint(sys.path)
|
160
|
-
|
161
|
-
['',
|
162
|
-
|
163
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python38.zip',
|
164
|
-
|
165
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8',
|
166
|
-
|
167
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/lib-dynload',
|
168
|
-
|
169
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages']
|
170
|
-
|
171
|
-
>>> sys.path.append('/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages')
|
172
|
-
|
173
|
-
>>> pprint.pprint(sys.path)
|
174
|
-
|
175
|
-
['',
|
176
|
-
|
177
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python38.zip',
|
178
|
-
|
179
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8',
|
180
|
-
|
181
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/lib-dynload',
|
182
|
-
|
183
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages',
|
184
|
-
|
185
|
-
'/Users/AM/.pyenv/versions/3.8.5/lib/python3.8/site-packages']
|
186
|
-
|
187
|
-
>>> quit()
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
```
|
192
|
-
|
193
193
|
|
194
194
|
|
195
195
|
参考にした文献
|