1

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.
3
  • How did you install numpy? And did you try the steps outlined in the instructions? Commented Jun 15, 2022 at 15:39
  • Used pip to install the numpy and followed all the steps outlined in the instructions to fix the issue but still getting the same issue. Commented Jun 15, 2022 at 15:43
  • 1
    It looks like you’re already using anaconda in your base env. Unfortunately, you may have broken this environment. I would uninstall anaconda, install miniconda, create a new environment, and install numpy in the new env, all with conda not pip. Or if that’s too daunting you could just reinstall anaconda but don’t try to mess with it - it already comes with numpy. Commented Jun 15, 2022 at 15:47

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.