microsoft / vscode-python

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

Miniconda3. ImportError: Unable to import required dependencies... #6843

Closed PavelD0770 closed 5 years ago

PavelD0770 commented 5 years ago
When running the script in VS Code, an error is issued:

C:\Users\user>C:/Python/Miniconda3/envs/myenv/python.exe d:/Test/Test.py Traceback (most recent call last): File "d:/Test/Test.py", line 1, in import pandas File "C:\Python\Miniconda3\envs\myenv\lib\site-ackages\pandasinit.py", line 17, in "Unable to import required dependencies:\n" + "\n".join(missing_dependencies) ImportError: Unable to import required dependencies: numpy: DLL load failed: The specified module was not found.

What am I doing.
  1. Install Miniconda3
  2. I create myenv virtual environment in Miniconda3
  3. Download packages there: pandas, numpy, etc.
  4. Launch VS Code (Microsoft's Python extension installed)
  5. I create a Python script file with text (for example): import pandas print ('pass ..')
  6. I select the virtual environment myenv and run the script on performance.
  7. I observe the above error :(

    Works from the console (miniconda), works from Visual Studio 2019, works from Pycharm too. From VS Code, it only works when changing to the virtual environment (venv) of Python 3.7, in which the packages from p. 3 are also installed. Those. the only problem is a bunch of VS Code and Miniconda3.

    A similar problem with numpy, matplotlib, scipy. C, for example, sqlalchemy, requests and some other third-party packages are all OK.

    Previously, VS code worked with the Miniconda3 virtual environment without any problems. Perhaps the problem appeared after installing and then uninstalling Anaconda Extension Pack.

Python 3.7.4 Miniconda3 4.7.10 (Python 3.7.3) Virtual env.: virtualenv (Python 3.7.4), conda envs. (Python 3.7.3) VS Code version: Code 1.36.1 (2213894, 2019-07-08T22:59:35.033Z) MS Python extension for Visual Studio Code 2019.6.24221 OS version: Windows_NT x64 10.0.17134

System Info CPUs Intel(R) Core(TM) i3-7100U CPU @ 2.40GHz (4 x 2400) GPU Status 2d_canvas: enabled flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled multiple_raster_threads: enabled_on native_gpu_memory_buffers: disabled_software oop_rasterization: disabled_off protected_video_decode: enabled rasterization: enabled skia_deferred_display_list: disabled_off skia_renderer: disabled_off surface_synchronization: enabled_on video_decode: enabled viz_display_compositor: disabled_off webgl: enabled webgl2: enabled Load (avg) undefined Memory (System) 5.89GB (0.37GB free) Process Argv
Screen Reader no VM 0%

Extensions (3): vscode-language-pack-ru MS- 1.37.3 python ms- 2019.6.24221 material-icon-theme PKi 3.8.1

PavelD0770 commented 5 years ago

The problem is that when choosing a virtual conda environment, this environment is not activated. To fix the problem, you must manually execute activate myenv (myenv is the environment name) in the VS code terminal.

PavelD0770 commented 5 years ago

Yes, specifying Path for conda is necessary. But in other IDEs it works without environment variables. Still, this is a problem with VS code or the Python extension package for Visual Studio Code

ericsnowcurrently commented 5 years ago

Thanks for letting us know about this, @PavelD0770. Before we take a deeper look, it looks like you are trying to use conda and virtualenv together. Is that the case? If so, why? Using conda alone should be sufficient. Keep in mind that the extension expects one or the other, not both.

PavelD0770 commented 5 years ago

Hello! At first I only used Python 3 without virtual environments to learn this language. Later I started to study Python course for data analysis. For this I installed Miniconda3. I created the conda virtual environment in order to gain new skills. And to my experiments and test tasks on the course program to perform separately. For the course I used Jupyter Notebook, and for my experiments - MS Visual Studio Code (VS Code I really liked).  Yes, for everything to work, I added the path to Miniconda to the Path environment variable. I didn't add anything to VS code settings. Only as a terminal chose cmd. Everything worked.At what point VS Code began to "swear" at the panda and numpy can not say for sure.

PavelD0770 commented 5 years ago

(The previous message did not finish. Accidentally sent is not complete.)

At first I only used Python 3 without virtual environments to learn this language. Later I started to study Python course for data analysis. For this I installed Miniconda3. I created the conda virtual environment in order to gain new skills.

And to my experiments and test tasks on the course program to perform separately. For the course I used Jupyter Notebook, and for my experiments - MS Visual Studio Code (VS Code I really liked).  For everything to work, I added the path to Miniconda to the Path environment variable. I didn't add anything to VS code settings. Only as a terminal chose cmd. Everything worked.

At what point VS Code began to "sweat" at the panda and numpy can not say for sure. I first thought this happened after installing the Anaconda extension package for VS Code. Deleted - did not help. I reviewed the possible settings, but nothing helped.

Helped only run the conda "activate myenv"command in vs code terminal. The script is started without any errors. I tried to install Python on another PC, then Miniconda, then envs. The mistake was repeated. The solution is also "activate myenv".

It looks like something with envs conda activation. MS Visual Studio Code extension to Python and PyCharm JetBrains in this environment are working without problems (from conda, with conda envs, c, Python, c Python virtualenv) Now I uninstalled Miniconda (not really necessary), I use only Python and virtualenv (configured for all the necessary tasks right now). It's okay!

ericsnowcurrently commented 5 years ago

So you are saying that everything is fine now that you have uninstalled miniconda?

meastream commented 5 years ago

Environment data

Expected behaviour

The activation of the conda virtual environment is done before the debugger starts.

Actual behaviour

The activation of the conda virtual environment is done after the debugger starts. Additionaly a problem with the activation of conda environments exist, see problem 1 and 2 later.

Steps to reproduce:

PS C:!work\pyTestApp>

- Run 2 Debugger (F5) with cmd.exe as Terminal
               C:\Miniconda3\envs\pyTestAppCondaEnv\python.exe c:\Users\admin\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 51446 c:\!work\pyTestApp\pyTestApp.py

Traceback (most recent call last): File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py", line 43, in main(ptvsdArgs) File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd__main.py", line 432, in main run() File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd__main__.py", line 316, in run_file runpy.run_path(target, run_name='main') File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "c:!work\pyTestApp\pyTestApp.py", line 4, in import numpy File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\site-packages\numpy\init__.py", line 140, in from . import _distributor_init File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\site-packages\numpy_distributor_init.py", line 34, in from . import _mklinit ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

c:!work\pyTestApp>C:/Miniconda3/Scripts/activate

(base) c:!work\pyTestApp>conda activate pyTestAppCondaEnv

(pyTestAppCondaEnv) c:!work\pyTestApp>


## Problem 1: Miniconda3 installation not correct
- Path environment variable is not configured properly for powershell
  - the `conda` command can not be found
- Path environment variable is configured properly for cmd.exe
  - no problems with cmd.exe

## Possible solution for problem 1
- run `conda init powershell`

(base) C:\Users\admin>conda init powershell no change C:\Miniconda3\Scripts\conda.exe no change C:\Miniconda3\Scripts\conda-env.exe no change C:\Miniconda3\Scripts\conda-script.py no change C:\Miniconda3\Scripts\conda-env-script.py no change C:\Miniconda3\condabin\conda.bat no change C:\Miniconda3\Library\bin\conda.bat no change C:\Miniconda3\condabin_conda_activate.bat no change C:\Miniconda3\condabin\rename_tmp.bat no change C:\Miniconda3\condabin\conda_auto_activate.bat no change C:\Miniconda3\condabin\conda_hook.bat no change C:\Miniconda3\Scripts\activate.bat no change C:\Miniconda3\condabin\activate.bat no change C:\Miniconda3\condabin\deactivate.bat no change C:\Miniconda3\Scripts\activate no change C:\Miniconda3\Scripts\deactivate no change C:\Miniconda3\etc\profile.d\conda.sh no change C:\Miniconda3\etc\fish\conf.d\conda.fish no change C:\Miniconda3\shell\condabin\Conda.psm1 no change C:\Miniconda3\shell\condabin\conda-hook.ps1 no change C:\Miniconda3\Lib\site-packages\xontrib\conda.xsh no change C:\Miniconda3\etc\profile.d\conda.csh modified C:\Users\admin\Documents\WindowsPowerShell\profile.ps1

==> For changes to take effect, close and re-open your current shell. <==

- now conda environment can be activated by vscode (as seen in last line of output)
  - Problem: now not only conda but full python is available in all powershell terminals in Windows and in vscode

Windows PowerShell Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

                          & 'C:\Miniconda3\envs\pyTestAppCondaEnv\python.exe' 'c:\Users\admin\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '51634' 'c:\!work\pyTestApp\pyTestApp.py'

Traceback (most recent call last): File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py", line 43, in main(ptvsdArgs) File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd__main.py", line 432, in main run() File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd__main__.py", line 316, in run_file runpy.run_path(target, run_name='main') File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "c:!work\pyTestApp\pyTestApp.py", line 4, in import numpy File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\site-packages\numpy\init__.py", line 140, in from . import _distributor_init File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\site-packages\numpy_distributor_init.py", line 34, in from . import _mklinit ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden. (base) PS C:!work\pyTestApp> C:/Miniconda3/Scripts/activate (base) PS C:!work\pyTestApp> conda activate pyTestAppCondaEnv (pyTestAppCondaEnv) PS C:!work\pyTestApp>


## Problem 2: Extend path for powershell not sufficient
- Extend path environment var with `C:\Miniconda3\condabin;`
- this makes conda command available but the activation ist still not successfull
    - no python paths in path environment variable

Windows PowerShell Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

                 > & 'C:\Miniconda3\envs\pyTestAppCondaEnv\python.exe' 'c:\Users\admin\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '51577' 'c:\!work\pyTestApp\pyTestApp.py'

Traceback (most recent call last): File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py", line 43, in main(ptvsdArgs) File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd__main.py", line 432, in main run() File "c:\Users\admin.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd__main__.py", line 316, in run_file runpy.run_path(target, run_name='main') File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "c:!work\pyTestApp\pyTestApp.py", line 4, in import numpy File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\site-packages\numpy\init__.py", line 140, in from . import _distributor_init File "C:\Miniconda3\envs\pyTestAppCondaEnv\lib\site-packages\numpy_distributor_init.py", line 34, in from . import _mklinit ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden. PS C:!work\pyTestApp> C:/Miniconda3/Scripts/activate PS C:!work\pyTestApp> conda activate pyTestAppCondaEnv

PS C:!work\pyTestApp> $env:path.Split(';') C:\WINDOWS\system32 C:\WINDOWS C:\WINDOWS\System32\Wbem C:\WINDOWS\System32\WindowsPowerShell\v1.0\ C:\WINDOWS\System32\OpenSSH\ C:\Miniconda3\condabin C:\Users\admin\AppData\Local\Microsoft\WindowsApps C:\Users\admin\AppData\Local\Programs\Microsoft VS Code\bin

PS C:!work\pyTestApp>


## Logs
Output for `Python` in the `Output` panel (`View`→`Output`, change the drop-down the upper-right of the `Output` panel to `Python`)

C:\Miniconda3\Scripts\conda.exe info --json

ericsnowcurrently commented 5 years ago

@meastream, for conda activation happening after the debugger starts, that is a known issue (see #6010 and #7425). For the other problems, please create a new issue.

brettcannon commented 5 years ago

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.