简体   繁体   English

将 Anaconda 与 Python 启动器一起使用时出现导入错误

[英]Import Error when using Anaconda with Python launcher

I installed Anaconda (Anaconda3-2020.07-Windows-x86_64, python 3.8).我安装了 Anaconda(Anaconda3-2020.07-Windows-x86_64,python 3.8)。 Following the installation guide, I didn't add Anaconda to the PATH environment variable.按照安装指南,我没有将 Anaconda 添加到 PATH 环境变量中。 After installation, it works well when using Anaconda Prompt to start python.安装后,使用Anaconda Prompt启动python时效果很好。

Problem occurs when I use Python Launcher to start python from CMD:当我使用 Python Launcher 从 CMD 启动 python 时出现问题:

In CMD, type "py" to launch python(The Python Launcher is able to find Anaconda python).在 CMD 中,输入“py”启动 python(Python Launcher 能够找到 Anaconda python)。 Then when I attempt to import numpy , I get the following error:然后,当我尝试导入numpy ,出现以下错误:

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

And when I attempt to import sqlite3 , I get the following error:当我尝试导入sqlite3 ,出现以下错误:

ImportError: DLL load failed while importing _sqlite3: %1 is not a valid Win32 application

If I use Anaconda Prompt to start python, I can suscessfully import numpy and sqlite3 .如果我使用 Anaconda Prompt 启动 python,我可以成功导入numpysqlite3 I checked sys.path under these two situations and they are exactly the same.我在这两种情况下检查了sys.path ,它们完全相同。

Why?为什么? What's the difference between the two situations?这两种情况有什么区别?

ps ps

I'm concerned with this problem because I built a website using "django + mod_wsgi + Apache", and when visiting the website from brwoser, the website got an "Internal Server Error".我很担心这个问题,因为我使用“django + mod_wsgi + Apache”构建了一个网站,当从 brwoser 访问该网站时,该网站出现“内部服务器错误”。 The error log shows that it is caused by the failure of importing numpy and sqlite3, just like the above errors.错误日志显示是导入numpy和sqlite3失败导致的,和上面的错误一样。

What's the difference between the two situations?这两种情况有什么区别?

The anaconda command prompt has added a bunch of paths to the PATH environment variable, eg for me it has added all of these locations: anaconda 命令提示符为 PATH 环境变量添加了一堆路径,例如对我来说,它添加了所有这些位置:

C:\ProgramData\Miniconda3
C:\ProgramData\Miniconda3\Library\mingw-w64\bin
C:\ProgramData\Miniconda3\Library\usr\bin
C:\ProgramData\Miniconda3\Library\bin
C:\ProgramData\Miniconda3\Scripts
C:\ProgramData\Miniconda3\bin
C:\ProgramData\Miniconda3\condabin

In some of these locations there are executables like python.exe so that calling python will launch the anaconda installed version.在其中一些位置有像python.exe这样的可执行文件,因此调用python将启动 anaconda 安装版本。 Other folders in this list contain .dll files, ie libraries that your modules might depend on (like numpy or sqlite that are interfaces to functions written in c/c++).此列表中的其他文件夹包含 .dll 文件,即您的模块可能依赖的库(如 numpy 或 sqlite,它们是用 c/c++ 编写的函数的接口)。 So even if you are calling the right python.exe, if the PATH is not set to include the locations of the neccessary dlls, then importing such packages will fail, as you can see in your error messages:因此,即使您正在调用正确的 python.exe,如果 PATH 未设置为包含必要 dll 的位置,则导入此类包将失败,如您在错误消息中所见:

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

What you can do:你可以做什么:

I am not an expert on configuring a django server, but by manually adding these locations to your PATH, you might be able to solve the issue.我不是配置 django 服务器的专家,但通过手动将这些位置添加到您的 PATH,您可能能够解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Anaconda导入matplotlib时出现unicode错误 - unicode error when import matplotlib using Anaconda 从Anaconda Launcher更新时出现错误消息 - Error msg when updating from Anaconda Launcher 在 anaconda 上导入 scipy 时出现 FileNotFoundError python - FileNotFoundError when import scipy on anaconda python 尝试在Anaconda中导入Tensorflow时出错 - Got an error when trying to import Tensorflow in Anaconda 无法使用Anaconda在python中导入psycopg2 - Unable to import psycopg2 in python using anaconda 无法使用Anaconda-Python导入scitools - Cannot import scitools using Anaconda-Python 使用 anaconda 可执行文件时将 Anaconda 包导入 sublime text 3 - import Anaconda packages into sublime text 3 when using anaconda executable 通过anaconda提示符执行python代码时,导入numpy起作用,但通过cmd运行时产生错误 - Import numpy works when python code executed through anaconda prompt but produces an error when run through cmd 在python 3.6(anaconda3)中执行“导入pyodbc”时,Jupyter Notebook引发错误:ImportError:DLL加载失败 - when executing “import pyodbc” in python 3.6 (anaconda3) Jupyter Notebook throws error: ImportError: DLL load failed 在 Anaconda 中使用 Spyder 使用 pandas_datareader.data 时导入错误 - Import Error when using pandas_datareader.data using Spyder in Anaconda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM