iPython: DLL load failed: The specified module could not be found; plain Python fine

回眸只為那壹抹淺笑 提交于 2019-12-18 09:05:46

问题


I keep getting this (well known) error in iPython. Yet, the same import works fine in plain Python. (Python 3.3.5, see details below)

iPython:

Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:37:12) [MSC v.1600 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 2.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import test1
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-ddb30f03c287> in <module>()
----> 1 import test1
ImportError: DLL load failed: The specified module could not be found.

Python (not only it loads fine, it also works):

$ python
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:37:12) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import test1
>>>

Now, Dependency Walker on test1.pyd shows this

[ ? ]  LIBGCC_S_DW2-1.DLL  Error opening file. The system cannot find the file specified (2).
[ ? ]  LIBSTDC++-6.DLL     Error opening file. The system cannot find the file specified (2).
[ ? ]  PYTHON33.DLL        Error opening file. The system cannot find the file spec

I even overwrote sys.path in iPython with the one from plain Python. The file test1.pyd is in C:\Test.

['c:\\Test',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\python33.zip',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\DLLs',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\lib',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\lib\\site-packages',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\lib\\site-packages\\FontTools',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\lib\\site-packages\\win32',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\lib\\site-packages\\win32\\lib',
 'c:\\WinPython-32bit-3.3.5.0\\python-3.3.5\\lib\\site-packages\\Pythonwin']

Why would the import work in plain Python but not in iPython?


回答1:


I have encountered the same problem. After hours looking and thinking I found out the cause. The difference is environment variables between interpreters (plain python and ipython or pycharm etc.). I think your can use %env in ipython to check the environment variables. In plain python, use (works in python 3.7):

import os
os.environ

Then if there are differences, maybe you should set the right one before your run.

Actually there are multiple ways to set envs. For example

os.environ['key']='value' #Both key and value are strings

or

os.putenv('key', 'value')

Here key is the name of the environment variable, and value is the value you want to set it to.

Hope this helps you.~~~///(^v^)\\~~~



来源:https://stackoverflow.com/questions/32302687/ipython-dll-load-failed-the-specified-module-could-not-be-found-plain-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!