无法使用python代码运行.bat文件:ImportError:无法导入所需的依赖项:numpy:

2024-06-16 10:46:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我用的是Python。我创造了一个叫做工程的环境。在than环境中,我安装了python 3.6、pandas 1.1.3、spyder 3.3.6、numpy 1.19.2以及更多。基本环境也有这些包,但不一定是相同的版本。在ENGINEERING env中,我在Spyder中创建了一个python脚本,在Spyder中运行时不会出现任何问题。然后,我想通过创建一个.bat文件来自动化该脚本,然后通过windows任务调度器使用该文件来自动化。我的.bat看起来像这样:

"C:\Users\alopo000\Anaconda3\envs\engineering\python.exe" "C:\Users\alopo000\Files\Python\Valid\Portf.py"
pause

运行.bat时,会收到一条错误消息:

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. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.6 from "C:\Users\alopo000\Anaconda3\envs\engineering\python.exe"
  * The NumPy version is: "1.19.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

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

我试过很多方法来解决这个问题。我去了他们建议的网站,在那里找不到任何东西。我卸载了pandas和numpy并重新安装了它们,但仍然出现了相同的错误。我没有尝试过的一件事是修复变量路径,主要是因为我在很多地方读到了不改变这些路径的内容。我可以改变他们,如果这是什么,但我想首先了解为什么不建议。我读到它可能会与其他版本的python产生问题,但不确定这是不是真的

是否需要激活.bat文件中的环境?问题是.bat文件试图在环境之外运行它吗?任何帮助都将不胜感激


Tags: and文件the版本numpy脚本pandas环境