推荐学习书目
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
bings666
V2EX  ›  Python

vscode ModuleNotFoundError: No module named

  •  
  •   bings666 · Jan 21, 2021 · 2358 views
    This topic created in 1943 days ago, the information mentioned may be changed or developed.
    各位好, 我在 pycharm 里面操作一个工程,里面有多个 py 文件,直接运行主文件 main.py,可以正常运行,但是把整个工程丢到 vscode 里面,运行 main.py ,就出现“ModuleNotFoundError: No module named” 的问题,请问这是什么原因呢,如有告知,万分感谢。
    平台 :win10 + anaconda 的虚拟环境
    公司电脑太卡了,每次打开 pycharm 要好半天,逼不得已迁入到 vscode
    5 replies    2021-01-21 15:00:41 +08:00
    Dragonish3600
        1
    Dragonish3600  
       Jan 21, 2021 via iPhone
    这不就是最基本的 module 导入问题么……
    bings666
        2
    bings666  
    OP
       Jan 21, 2021
    @ladypxy 是的,加入了类似
    import sys
    sys.path.append('D:\\****')
    的代码就可以了
    我的疑问是为什么 pycharm 不加就可以直接运行不报错
    Jirajine
        3
    Jirajine  
       Jan 21, 2021 via Android
    因为你没有指定使用相同的 Python 环境。
    bings666
        4
    bings666  
    OP
       Jan 21, 2021
    @Jirajine 是一样,我看了终端里面的 python 路径,是 anaconda 创建的虚拟环境里面的 终端打印 是 ***/python.exe main.py
    simple2025
        5
    simple2025  
       Jan 21, 2021
    一般是 pythonpath 的问题,pycharm 会自动加入工作目录
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1299 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 23:44 · PVG 07:44 · LAX 16:44 · JFK 19:44
    ♥ Do have faith in what you're doing.