AlPuRh
AlPuRh

Reputation: 11

Importing the numpy c-extensions failed in VS Code

Getting error with VS Code in installing pkg Numpy and Pandas. Any solution on how we can fix the issue? Thanks.

Error:

from . import _distributor_init
Traceback (most recent call last):
File ".\Form_validate.py", line 1, in <module>
import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy:



IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!



Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\ProgramData\Anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log



- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.



Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.



Original error was: DLL load failed: The specified module could not be found.

Upvotes: 1

Views: 4863

Answers (2)

danespin
danespin

Reputation: 21

This happens because if VS Code is launched apart, as usual, it will recognize Python from Anaconda setup but will have trouble loading imports.

Fix: Close VS Code. Then open anaconda shell, i.e., the terminal, and from there launch VS code with the comand:

Anaconda_prompt> code

You'll see terminal inside VS Code will run automatically the command: conda activate base Then run your program again within VS Code, and should work fine as expected.

Upvotes: 2

MingJie-MSFT
MingJie-MSFT

Reputation: 9417

There are two solutions.

The first is to reinstall numpy, including its architecture tools. Reinstall the package by using the following code in sequence:

pip uninstall -y numpy

pip uninstall -y setuptools

pip install setuptools

pip install numpy

The second solution is to add the path to the environment variable. In fact, pylance did not find this file because

File "C:\ProgramData\Anaconda3\lib\site-packages\pandas_init_.py", line 17,

If you try to make Python output sys.path, you will find that it is anaconda3 instead of Anaconda3.

So, adding the path to environment variable can solve it.

Upvotes: 1

Related Questions