我想在我的mac上使用python中的watchdog模块。我已经通过自制软件下载了python3。( $ which python3
结果为/usr/local/bin/python3
;$ which python
结果为/usr/bin/python
。)在安装了homebrew、python3和automatically pip3之后(由于homebrew),我输入了命令$ pip3 install watchdog
。watchdog的安装运行良好,当我输入$ pip3 list
时,watchdog显示为已安装的软件包。另一方面,当我执行下面的脚本时,我得到一个错误,告诉我没有找到watchdog.observer。
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
# pip install watchdog for these packages to work
import os
import json
import time
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
for filename in os.listdir(folder_to_track):
src = folder_to_track + "/" + filename
new_destination = folder_destination + "/" + filename
os.rename(src, new_destination)
folder_to_track = "/Users/eve/Desktop/folder1"
folder_destinatiom = "/Users/eve/Desktop/folder2"
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, folder_to_track, recursive=True)
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
observer.stop()
observer.join()
错误:
Traceback (most recent call last):
File "/Users/eve/Desktop/auto_ideas.py", line 1, in <module>
from watchdog.observers import Observer
ImportError: No module named watchdog.observers
在我的编程环境VS Code中,我可以使用python 2.6.9. 64Bit, saved at /usr/bin/python2.6
或python 2.7.10 64Bit, saved at /usr/bin/python
、python 3.7.6 64Bit, saved at /usr/local/bin/python3
或python 3.7.6 64Bit, saved at /usr/local/opt/python/bin/python3.7
来执行脚本。这些选项对我都不起作用--我每次尝试都会得到相同的错误。有没有人知道,我怎么才能让看门狗在这种情况下工作?提前感谢
发布于 2020-01-20 23:10:04
同样的问题!我不知道为什么,但是用python.exe path运行我的脚本是有效的!
C:\Python37\python.exe c:\rw_projects\mtl_error_notifier\mtl_error_notifier.py
https://stackoverflow.com/questions/59685763
复制相似问题