首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >导入numpy c-扩展在VS代码中失败

导入numpy c-扩展在VS代码中失败
EN

Stack Overflow用户
提问于 2022-06-15 15:28:06
回答 2查看 920关注 0票数 0

在安装pkg、Numpy和Pandas时出现VS代码错误。我们如何解决这个问题有什么解决办法吗?谢谢。

错误:

代码语言:javascript
运行
复制
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.
EN

回答 2

Stack Overflow用户

发布于 2022-06-16 02:07:07

有两种解决办法。

首先是重新安装numpy,包括它的体系结构工具。按照顺序使用以下代码重新安装包:

代码语言:javascript
运行
复制
pip uninstall -y numpy

pip uninstall -y setuptools

pip install setuptools

pip install numpy

第二个解决方案是向环境变量添加路径。事实上,pylance找不到这个文件是因为

"C:\ProgramData\Anaconda3\lib\site-packages\pandas_init_.py",文件

第17行

如果您试图使Python sys.path,您会发现它是anaconda3而不是Anaconda3

因此,将路径添加到环境变量可以解决这个问题。

票数 1
EN

Stack Overflow用户

发布于 2022-11-14 15:39:56

这是因为如果VS代码是分开启动的,像往常一样,它将从Anaconda安装程序中识别Python,但在加载导入时会遇到困难。

修正:关闭对代码。然后打开anaconda shell,即终端,然后用comand启动VS代码:

Anaconda_prompt>代码

您将看到VS代码内部的终端将自动运行命令: conda activate base,然后在VS Code中再次运行您的程序,并且应该像预期的那样正常工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72634054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档