无法在 PyCharm 中加载 DLL python 模块。在 IPython 中运行良好

发布于 2024-11-03 22:03:08 字数 1248 浏览 1 评论 0原文

当我使用 Enthought Python Distribution 附带的 IPython 时,我可以很好地导入 pyvision 包。但是,当我尝试在 PyCharm 1.2.1 中导入 pyvision 时,出现以下错误:

  File "C:\Python27\lib\site-packages\pyvision\__init__.py", line 146, in <module>
    from pyvision.types.img import Image,OpenCVToNumpy,NumpyToOpenCV
  File "C:\Python27\lib\site-packages\pyvision\types\img.py", line 43, in <module>
    import numpy
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module>
    import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 13, in <module>
    from polynomial import *
  File "C:\Python27\lib\site-packages\numpy\lib\polynomial.py", line 17, in <module>
    from numpy.linalg import eigvals, lstsq
  File "C:\Python27\lib\site-packages\numpy\linalg\__init__.py", line 48, in <module>
    from linalg import *
  File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 23, in <module>
    from numpy.linalg import lapack_lite
ImportError: DLL load failed: The specified module could not be found.

我是否缺少 Windows 中的某些路径设置?

When I use the IPython included with Enthought Python Distribution, I can import the pyvision package just fine. However, when I try to import pyvision inside of PyCharm 1.2.1, I get the following errors

  File "C:\Python27\lib\site-packages\pyvision\__init__.py", line 146, in <module>
    from pyvision.types.img import Image,OpenCVToNumpy,NumpyToOpenCV
  File "C:\Python27\lib\site-packages\pyvision\types\img.py", line 43, in <module>
    import numpy
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module>
    import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 13, in <module>
    from polynomial import *
  File "C:\Python27\lib\site-packages\numpy\lib\polynomial.py", line 17, in <module>
    from numpy.linalg import eigvals, lstsq
  File "C:\Python27\lib\site-packages\numpy\linalg\__init__.py", line 48, in <module>
    from linalg import *
  File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 23, in <module>
    from numpy.linalg import lapack_lite
ImportError: DLL load failed: The specified module could not be found.

Am I missing some path settings in Windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

活泼老夫 2024-11-10 22:03:08

我也有同样的问题。我正在使用 Winpython32 并尝试导入 win32com。除了 PyCharm 之外,在任何地方都可以工作(我尝试过)。 sys.pathos.environ['PYTHONPATH'] 在 Pycharm 内有一些额外的条目,但与在其他地方运行时相比,没有丢失任何内容。

解决方案是在 Winpython 控制台中启动 Pycharm,而不是使用快捷方式。

sys.pathos.environ['PYTHONPATH'] 没有改变。 os.environ['PATH'] 设置了几个附加条目,所有条目都与 python 安装相关。在这一点上,我怀疑这与“非标准”安装有关。 Winpython32 试图“可移植”,而其他类似问题的报告是在使用 Enthought 或 Python(x,y) 时出现的。

手动添加:

 C:\WinPython-32\python-2.7.6\
 C:\WinPython-32\python-2.7.6\DLLs
 C:\WinPython-32\python-2.7.6\Scripts

到系统路径(Windows 中的全局 PATH 环境变量)解决了问题,而无需在 Winpython 命令行中运行 Pycharm。注意:单独使用C:\WinPython-32\python-2.7.6\Scripts并不能解决这个问题。

I had the same problem. I'm using Winpython32 and trying to import win32com. Worked everywhere (I tried) except in PyCharm. sys.path and os.environ['PYTHONPATH'] had some extra entries inside Pycharm, but nothing is missing compared to when run elsewhere.

The solution was to start Pycharm within the Winpython console and not using the shortcut.

sys.path and os.environ['PYTHONPATH'] did not change. os.environ['PATH'] had several additional entries set, all related to the python installation. At this point I suspect it has to do with "non-standard" installations. Winpython32 tries to be "portable", while other reports of similar problems are when using Enthought or Python(x,y).

Manually adding:

 C:\WinPython-32\python-2.7.6\
 C:\WinPython-32\python-2.7.6\DLLs
 C:\WinPython-32\python-2.7.6\Scripts

to the system path (the global PATH environment variable in Windows) solved the problem without having to run Pycharm within the Winpython command line. Note: C:\WinPython-32\python-2.7.6\Scripts alone did not solve it.

分开我的手 2024-11-10 22:03:08

我以前也遇到过这个问题,似乎通过修复 Enthought 就可以解决。

编辑:我刚刚检查过,我的一个 f2py 项目仍然遭受这个确切的错误。修复 Enthought 不起作用。我的问题的解决方案实际上在于修复 Windows 路径变量。您需要确保 c:\Python27\Scripts (或等效的)位于路径中。此外,这一点非常重要,请确保全局和用户路径环境变量中的每个条目都没有尾部斜杠。这会破坏 Windows 上的 GNU make 实用程序。

I've had that problem before, and it seemed to get fixed by repairing Enthought.

EDIT: I just checked, one of my f2py projects was still suffering from this exact error. Repairing Enthought did not work. The solution to my problem actually lay in fixing the Windows path variable. You need to make sure c:\Python27\Scripts (or your equivalent) is in the path. Furthermore, and this is VERY important, make sure each entry in the global and user path environment variables has NO trailing slashes. This breaks the GNU make utility on Windows.

爱*していゐ 2024-11-10 22:03:08

添加到您的 PATH 环境变量

C:\Python27
C:\Python27\DLLs
C:\Python27\Scripts

Add to your PATH environment variable

C:\Python27
C:\Python27\DLLs
C:\Python27\Scripts
浪荡不羁 2024-11-10 22:03:08

这是 PyCharm 中一个非常令人沮丧的错误。即使您在 PyCharm 中设置 virtualenv,“python 控制台”也默认为系统 python。当您安装 PyCharm 时,大概您在 64 位计算机上使用了 win32 python。

转到 file>settings>Build, Execution, Deployment>Console>Python Console 并将 Python Interpreter 从系统版本更改为您的 virtualenv。

当然,PyCharm 不会立即刷新它。您必须关闭项目并重新打开它。

要验证此操作是否成功,请打开 Python 控制台 (Tools>Python Console) 并检查输出的第一行:它应该指向您的 python.exe虚拟环境,不是系统python。

This is a pretty frustrating bug in PyCharm. Even if you set your virtualenv from within PyCharm, the "python console" defaults to the system python. When you installed PyCharm, presumably you used a win32 python on a 64 bit machine.

Go to file>settings>Build, Execution, Deployment>Console>Python Console and change the Python Interpreter from the system version to your virtualenv.

Of course, PyCharm doesn't immediately refresh it. You have to close your project and reopen it.

To verify this was successful, open the Python Console (Tools>Python Console) and check the very first line of the output: it should point to the python.exe of your virtual environment, not the system python.

单调的奢华 2024-11-10 22:03:08

我有同样的问题(使用另一个包),并且我不想修改 Windows 路径。
我可以在 pycharm 控制台中非常粗略地解决这个问题,方法是创建一个 python 脚本,该脚本更新文件 -settings-console-pathon 控制台中的 sys.path 和 os.environ['PATH'] - 启动脚本。它仅在我使用“时才有效”工具- python shell”

仍然在运行选项中不起作用。我什至尝试创建一个虚拟环境,添加 activate.bat 的路径,但在 pycharm 中它不起作用(在命令提示符下它起作用)(如 virtualenv 可以找到重定位的 libraires(如 MySQLdb 的 mysqlclient lib)
我在 python 解释器选项中明确设置了路径,但它不起作用。(如 https://stackoverflow.com/a 中建议的那样/24206781/1136458)

I have the same problem (with another package) and I don't want to modify windows path.
I could solve it very roughly in the pycharm console, by creating a python script which updates sys.path and os.environ['PATH'] in file -settings-console-pathon console - starting script.It works only when I use "tools- python shell"

Still it doesn't work in the run options. I even tried to create a virtual environment, add the path to the activate.bat but in pycharm it doesn't work (from command prompt it does) (as suggested in virtualenv that can find relocated libraires (like mysqlclient lib for MySQLdb) )
I explicilty set the path in the python interpreter option but it doesn't work.(as suggested in https://stackoverflow.com/a/24206781/1136458)

爱殇璃 2024-11-10 22:03:08

输入图片此处描述我找不到链接,但我保存了这张图片 - 希望对您有用

enter image description hereI couldn't find the link but I saved this pic - hopefully works for you

绝對不後悔。 2024-11-10 22:03:08

我很抱歉我的解释很长,而且可能不是最清楚的,但这是我能做的最好的描述我的经历的事情。

第一次安装后我遇到了同样的问题,这就是我解决它的方法:

我注意到有一些设置,如其他答案所示,告诉 pyCharm 要使用哪些解释器和环境管理器,我确信问题出在设置上这些选项,但我不知道如何,所以我开始搜索。

设置解释器

我或多或少遵循了标准教程,假设在某些时候我会在项目文件夹中使用新创建的 virtualenv 。我最初收到 DLL 错误,但当我确保解释器设置指向有效的可执行文件时。

此处解释了如何执行此操作。

设置环境

此时错误消失了,但我又出现了新的错误。
此时的问题是我无法导入任何模块,因为找不到它们。
这是因为我在新创建的 virtualenv 中工作,基本上是原始安装,没有安装任何模块。我确信有更进化的解决方案(在 virtualenv 中安装模块),但我只是在寻找使代码能够工作的方法,所以我将环境设置为使用我的 anaconda 常用开发环境。

对我来说,在Windows上使用conda(使用conda activate激活开发环境后)然后(参见..../anaconda-python-where-are-the-virtual-environments-stored 对于其他系统)。
其中 python 给出解释器的路径
conda info --envs 为我提供了我想要使用的现有环境。

这为我解决了一切。

I apologize for my explanation being long and probably not the best of clarity, but this is the best I could do to describe my experience.

I was having the same problem after first installation and this is how I solved it:

I had noticed there are some settings, as indicated in other answers, that tell pyCharm which interpreters and environment managers to use and I was sure the problem was with setting these options, but I was not sure how, so I started searching.

Setting interpreter

I had more or less followed the standard tutorial, assuming in some point I would have used newly created virtualenv inside my project folder. I was initially getting the DLL error, but as I made sure the interpreter settings were pointing at a valid executable.

Here it is explained how to do this.

Setting environment

at this point the error disappeared, but I had progressed towards a new error.
The problem at this point I was not being able to import any module as they were not found.
This is because I was working inside the newly created virtualenv, basically a pristine installation, with no modules installed. I am sure there are more evolved solutions (install modules in the virtualenv), but I was just looking for making the code to work, so I set the environment to use my anaconda usual development environment.

For me, with conda on windows (after activating the development environment with conda activate) then (see ..../anaconda-python-where-are-the-virtual-environments-stored for other systems).
where python gives the path to the interpreter
conda info --envs gives me the existing environment that I want to use.

This fixed everything for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文