我想在mac上使用python中的看门狗模块。
我已经通过自制下载了python3。($ which python3
导致/usr/local/bin/python3
;$ which python
导致/usr/bin/python
。)
在我安装了homebrew、python3和自动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代码中,我可以使用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
执行脚本。这些选项中没有一个适合我——我每次尝试都会遇到同样的错误。有人知道,在这种情况下,我如何让看门狗工作吗?提前谢谢
同样的问题!我不知道为什么,但是用python.exe路径运行我的脚本是可行的
相关问题 更多 >
编程相关推荐