V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
shinonome
V2EX  ›  Python

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

  •  
  •   shinonome · 2023-03-02 14:39:06 +08:00 · 866 次点击
    这是一个创建于 419 天前的主题,其中的信息可能已经有所发展或是发生改变。

    运行命令

    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-03-02 14:45:10 +08:00
    找到修改的办法了,请问这个问题产生的原因是什么呢,是因为我设置过
    alias python="/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8"
    xhldtc
        2
    xhldtc  
       2023-03-02 15:43:25 +08:00
    看你提供的信息,你的系统里面应该有两个 python 版本,3.8 和 3.10 ,python 对应是 3.8, python3 对应的是 3.10, 3.8 那个版本没有装 watchdog 这个 module ,所以报错。可以把 python 和 python3 都指向同一个版本,不过最好还是用 virtual env 这种工具来管理,一个项目一个 env
    IamUNICODE
        3
    IamUNICODE  
       2023-03-02 16:30:56 +08:00
    看看 vscode 的 Python 设置路径在哪
    ZAXON
        4
    ZAXON  
       2023-03-02 16:31:27 +08:00
    @shinonome 二楼是正解,建议不要用 `alias` 来设置 python ,可以使用 `ln` 。如果需要多版本的话,建议是保留 python3.8 和 python3.10, 或者是用 pipenv / miniconda 之类的工具来管理多版本,而非是直接替换 python, 因为有些系统的命令会用到 python ,比如我之前遇到的 centos 的某个版本, yum 的功能依赖 python -> python2, 如果改成 python -> python3 就会报错了,当然这是少数情况了。
    datou
        5
    datou  
       2023-03-02 16:41:34 +08:00
    python -m pip install watchdog
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3252 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:46 · PVG 21:46 · LAX 06:46 · JFK 09:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.