microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

ModuleErrorNotFound for some installed packages #15424

Closed jonathanH1983 closed 3 years ago

jonathanH1983 commented 3 years ago

Issue Type: Bug

1.Create virtual environment. 2.Install flask. Run code on cmd and vscode to import flask. Successful result. 3.Create simple module. Import module in vscode. Successful result. 4.Install tensorflow, pendulum, and pandas. Execute code in cmd to import packages and print version. Successful result. 5.Import packages in vscode. Encounter ModuleNotFoundError .

For some reason the installed packages work when I execute them on CMD but not in VSCODE. I'm not using Anaconda.

Using python 3.8.5. Extension version: 2021.1.502429796 VS Code version: Code 1.53.2 (622cb03f7e070a9670c94bae1a45d78d7181fbd4, 2021-02-11T11:48:04.245Z) OS version: Windows_NT x64 10.0.19041

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz (4 x 2400)| |GPU Status|2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled| |Load (avg)|undefined| |Memory (System)|7.86GB (2.05GB free)| |Process Argv|--crash-reporter-id d4a77182-647a-4bc2-a7c0-a9d197e52577| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 pythonvspyt617cf:30253240 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstry914:30256638 pythonvsdeb440:30248342 pythonvsded773:30248341 vstes627:30244334 pythonvspyt600cf:30251589 ```
jonathanH1983 commented 3 years ago

I tried using jupyter notebook and my code worked. A simple: import tensorflow as tf print(tf.version)

I've read that you don't necessarily have to have jupyter for tensorflow to work but I can't seem to make it run on pure vscode .py file.

karthiknadig commented 3 years ago

@jonathanH1983 Is the environment activated? Can you try and start vscode from an activated environment using code . to launch it?

jonathanH1983 commented 3 years ago

I have always activated my environment when I encountered my problem (venv\scripts\activate).

Not sure if I did this right cos I'm not familiar with code . but this is what I did from CMD after activating the virtual environment and it launched VSCODE:

(venv) C:\Users\Jonathan\Documents\Programming Folder\Scratch>code .

After VSCODE finished loading the extensions I was able to successfully execute a simple tensorflow code: import tensorflow as tf print(tf.__version__)

Output: Code 2021-02-18 17:51:26.495267: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2021-02-18 17:51:26.515115: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2.4.1

I understand that the first 2 messages can be ignored since I have not set up my cuda but I was able to get the version out this time.

I also did a simple import code for pandas and pendulum and it completed without error messages.

Do I use code . from now on? What does this syntax mean?

karthiknadig commented 3 years ago

code . the 'dot' means current directory. That command is just launching VS Code from which ever directory you are in. You will only need to do this if the environment is not getting activated from VS Code correctly.

jonathanH1983 commented 3 years ago

OK. I'll guess I just have to do use this each time I encounter this problem. Thanks a lot!

karthiknadig commented 3 years ago

@jonathanH1983 We have plans to address the issue with failing activations. This is a just a workaround until we are able to fix it entirely.