简体   繁体   中英

Python3 ModuleNotFoundError: No module named 'watchdog'

I have pip3 installed watchdog into my python3 venv.

which pip3 shows: /Users/user/qwerty/project/bin/pip3

which pythons hows: /Users/user/qwerty/project/bin/python

When i enter the Python interpreter and 'import watchdog' it works fine. However as soon as i run a nose2 Test it fails to import watchdog:

(project) Users-MacBook-Pro:project user$ python3 Python 3.9.9 (main, Nov 21 2021, 03:23:42) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import watchdog

The error i am getting is:

ImportError: Failed to import test module: test_myscript Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/nose2/plugins/loader/discovery.py", line 201, in _find_tests_in_file module = util.module_from_name(module_name) File "/usr/local/lib/python3.9/site-packages/nose2/util.py", line 77, in module_from_name import (name) File "/Users/user/qwerty/project/project/tests/myscript.py", line 5, in from whippetwatcher import WhippetWatcher File "/Users/user/qwerty/project/project/myscript.py", line 3, in from watchdog import Observer ModuleNotFoundError: No module named 'watchdog'

I have tried the answer on another thread with similar issue but it did not fix this: ModuleNotFoundError: No module named 'watchdog'

A colleague helped solved this but posting for reference:

I deactivated my python venv, pip uninstalled nose2, then activated the venv again and it worked.

I think the problem was a pip3 install of nose2 made it global so the venv was using that nose2 and not the environments nose2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM