2

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?

John H
  • 21
  • 1
  • 4
  • Could you add the startup sequence for iPython, that is, show the output information you get when you start iPython? (Like you've done for Python.) –  Aug 31 '15 at 01:20
  • Solved my problem in the sense that I can now use iPython. It depends on the way I start iPython, but that's an entirely different story. If I start it from the command line by simply invoking "ipython", then it works fine. However, If I start it by invoking a bat file that contains the command "ipython" (i.e., from the menu), then it fails. But whatever goes wrong does not seem to be reflected in either the startup sequence or sys.path - which is the same in both cases. – John H Aug 31 '15 at 02:08
  • To eliminate any doubt over which ipython, both ipython and ipython3 in WinPython-32bit-3.3.5.0\python-3.3.5\Scripts work when invoked directly, fail when invoked via a bat file. – John H Aug 31 '15 at 02:20

1 Answers1

0

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^)\\~~~

Imperishable Night
  • 1,503
  • 9
  • 19
galabrim
  • 1
  • 1
  • 3