||
在最近的工作中我想使用Python去调用IDL进而完成一个复杂程序的自动化处理,然后在主程序结束后通知我程序的结果。
找到方法使得Python可以顺利调用IDL的pro脚本
执行pro脚本后回到Python并调用发送短信至指定手机以通知我程序已经运行完成
其中,可以使用阿里云的SMS服务或者twilio制作服务器短信通知(以后再写)。
pyidl是很久之前的包,依赖于numarray。但是,numarray是numpy的前身,现在numarray已经弃用了,使用pip是无法安装的,即使去查找,最后下载下来的也是numpy。
当然我们可以在安装脚本setup.py里改numarray为numpy,但是会报出以下一系列的错误,如果有人知道如何解决,可以告诉我哦~
running install running build running build_py running build_ext building '_pyIDL' extension C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Imodule "-ID:\program files\IDL85\IDL85\external\include" "-ID:\program files\python\include" "-ID:\program files\python\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /EHsc /Tpmodule\bindings.cc /Fobuild\temp.win-amd64-3.7\Release\module\bindings.obj bindings.cc C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Imodule "-ID:\program files\IDL85\IDL85\external\include" "-ID:\program files\python\include" "-ID:\program files\python\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /EHsc /Tpmodule\_pyIDLmodule.cc /Fobuild\temp.win-amd64-3.7\Release\module\_pyIDLmodule.obj _pyIDLmodule.cc module\_pyIDLmodule.cc(18): error C3861: “Py_InitModule4”: 找不到标识符 error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
当然,我们还可以使用自家的已经安装在IDL路径里的package,找到相应的安装目录并执行安装脚本,但是IDL的版本必须是8.5及其以上哦~(我的IDL8.5下虽然有那个文件idlpy.py,但是没有安装文件setup.py)
以下是参考的路径和安装方法:
cd C:\Program Files\Harris\IDLxx\lib\bridges python setup.py install
经过了一波搜索之后,我终于找了令人满意的package,就是pIDLy
虽然它为Python2.6.x写的,但是在Python3.X依然好用~
Github:https://github.com/anthonyjsmith/pIDLy
注意:由于pIDLy依赖pexpect包,但是pexpect包的spawm函数在Windows下是不可用的,所以pIDLy只能在Linux和MacOS下运行!!!
pip install pidly
下载源文件(tar.gz),解压后[python setup.py install ]
Usage: Initiate: >>> import pidly >>> idl = pidly.IDL() Or: idl = pidly.IDL('/path/to/idl') Execute commands: >>> idl('x = total([1, 1], /int)') Retrieve values: >>> print(idl.ev('x')) 2 Or (slightly slower): >>> print(idl.x) 2 Evaluate expressions: >>> print(idl.ev('x ^ 2')) 4 Use cache (IDL save) to handle large arrays: >>> idl('x=[1,2,3,4,5,6]') >>> print(idl.ev('x', use_cache=True)) [1 2 3 4 5 6] Transfer a list of IDL variables, using cache: >>> idl('y=[1,2,3,4,5,6]') >>> xy = idl.ev_list(['x','y'], use_cache=True) >>> print(sorted(xy.keys())) ['x', 'y'] >>> print(xy['x']) [1 2 3 4 5 6] Assign value from Python expression: >>> idl.x = 2 + 2 >>> print(idl.x) 4 Or: >>> idl('x', 2 + 2) >>> print(idl.x) 4 Perform IDL function on Python expression(s): >>> idl.func('reform', range(4), 2, 2) array([[0, 1], [2, 3]]) Or (slightly slower): >>> idl.reform(range(4), 2, 2) array([[0, 1], [2, 3]]) With keywords (/L64 -> L64=True or L64=1) >>> x = idl.histogram(range(4), binsize=3, L64=True) >>> print(x) [3 1] >>> print(x.dtype) int64 IDL procedure with Python argument(s): >>> idl.pro('plot', range(10), range(10), xstyle=True, ystyle=True) Interactive mode: >> idl.interact() IDL> print, x 4 IDL> ^D >>> Close: >>> idl.close() pIDLy supports the transfer of: * ints, longs, ... * floats, doubles, ... * strings * arrays of the above types, with arbitrary size and shape * dictionaries <-> structures & lists of dicts <-> arrays of structures but with certain limitations on transfer from Python to IDL [NB if getting Syntax Errors when passing large arrays to IDL, try using >> idl = pidly.IDL(long_delay=0.05) default is 0.02.]
ENVI-IDL技术殿堂IDL 8.5中的Python Bridge
钱磊老师运行简单的IDL脚本
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-25 03:29
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社