shinonome
V2EX  ›  Python

vscode 中虚拟环境 Python 提示没有库

By shinonome at 2023 年 3 月 2 日 · 1931 次点击

运行命令

python -u "sync.py"

就提示

*ModuleNotFoundError: No module named 'watchdog'

运行

python3 -u "sync.py"

是正常的,萌新有点搞不懂了 怎么将命令更改为 Python3 呢 这个问题是怎么产生的呢 系统为 macos 13.2

Python 3.10.8
(anime) ➜  anime-tools python3 -V
Python 3.10.8

pip list 显示安装库如下

pip        23.0.1
setuptools 67.4.0
watchdog   2.3.1
wheel      0.38.4
5 条回复  •  2023-03-02 16:41:34 +08:00
shinonome
   1
shinonome  
OP
   2023 年 3 月 2 日
找到修改的办法了,请问这个问题产生的原因是什么呢,是因为我设置过
alias python="/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8"
吗
goofish
   2
goofish  
   2023 年 3 月 2 日
看你提供的信息,你的系统里面应该有两个 python 版本,3.8 和 3.10 ,python 对应是 3.8, python3 对应的是 3.10, 3.8 那个版本没有装 watchdog 这个 module ,所以报错。可以把 python 和 python3 都指向同一个版本,不过最好还是用 virtual env 这种工具来管理,一个项目一个 env
IamUNICODE
   3
IamUNICODE  
   2023 年 3 月 2 日
看看 vscode 的 Python 设置路径在哪
ZAXON
   4
ZAXON  
   2023 年 3 月 2 日
@shinonome 二楼是正解,建议不要用 `alias` 来设置 python ,可以使用 `ln` 。如果需要多版本的话,建议是保留 python3.8 和 python3.10, 或者是用 pipenv / miniconda 之类的工具来管理多版本,而非是直接替换 python, 因为有些系统的命令会用到 python ,比如我之前遇到的 centos 的某个版本, yum 的功能依赖 python -> python2, 如果改成 python -> python3 就会报错了,当然这是少数情况了。
datou
   5
datou  
   2023 年 3 月 2 日
python -m pip install watchdog
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
© 2026 V2EX · 31ms · 3.9.8.5