使用控件时,Slycot无法导入

时间:2019-02-11 12:11:45

标签: python-3.x controls anaconda python-import python-control

我似乎无法使control.ss2tf()函数在状态空间MIMO系统中正常工作。该功能非常适合SISO系统。

以下代码用于运行模块:

control.ss2tf(A,B,C,D)

结果输出表明未安装slycot模块。

然后我尝试安装slycot

pip install slycot

此命令给出以下输出:

  Failed building wheel for slycot
  Running setup.py clean for slycot
Failed to build slycot
Installing collected packages: slycot
  Running setup.py install for slycot ... error
    Complete output from command c:\users\wian\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Wian\\AppData\\Local\\Temp\\pip-install-cmcxwtts\\slycot\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Wian\AppData\Local\Temp\pip-record-_n6gj2yv\install-record.txt --single-version-externally-managed --compile:
    Running from numpy source directory.
    running install
    running build
    running config_cc
    unifing config_cc, config, build_clib, build_ext, build commands --compiler options
    running config_fc
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
    running build_src
    build_src
    building py_modules sources
    building extension "slycot._wrapper" sources
    f2py options: []
      adding 'build\src.win-amd64-3.6\build\src.win-amd64-3.6\slycot\src\fortranobject.c' to sources.
      adding 'build\src.win-amd64-3.6\build\src.win-amd64-3.6\slycot\src' to include_dirs.
      adding 'build\src.win-amd64-3.6\slycot\src\_wrapper-f2pywrappers.f' to sources.
    build_src: building npy-pkg config files
    running build_py
    copying slycot\version.py -> build\lib.win-amd64-3.6\slycot
    copying build\src.win-amd64-3.6\slycot\__config__.py -> build\lib.win-amd64-3.6\slycot
    running build_ext
    Looking for python36.dll
    Building import library (arch=AMD64): "c:\users\wian\anaconda3\libs\libpython36.a" (from c:\users\wian\anaconda3\python36.dll)
    objdump.exe: c:\users\wian\anaconda3\python36.dll: file format not recognized
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Wian\AppData\Local\Temp\pip-install-cmcxwtts\slycot\setup.py", line 241, in <module>
        setup_package()
      File "C:\Users\Wian\AppData\Local\Temp\pip-install-cmcxwtts\slycot\setup.py", line 233, in setup_package
        setup(**metadata)
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\core.py", line 171, in setup
        return old_setup(**new_attr)
      File "c:\users\wian\anaconda3\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "c:\users\wian\anaconda3\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "c:\users\wian\anaconda3\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "c:\users\wian\anaconda3\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\command\install.py", line 62, in run
        r = self.setuptools_run()
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\command\install.py", line 36, in setuptools_run
        return distutils_install.run(self)
      File "c:\users\wian\anaconda3\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "c:\users\wian\anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\wian\anaconda3\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\command\build.py", line 47, in run
        old_build.run(self)
      File "c:\users\wian\anaconda3\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "c:\users\wian\anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\wian\anaconda3\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\command\build_ext.py", line 116, in run
        force=self.force)
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\ccompiler.py", line 765, in new_compiler
        compiler = klass(None, dry_run, force)
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 103, in __init__
        build_import_library()
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 415, in build_import_library
        return _build_import_library_amd64()
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 471, in _build_import_library_amd64
        generate_def(dll_file, def_file)
      File "c:\users\wian\anaconda3\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 301, in generate_def
        raise ValueError("Symbol table not found")
    ValueError: Symbol table not found

我读到这是由于系统上未安装FORTRAN编译器所致。因此,我在Ming32上安装了gfortran。为了验证安装,我运行了以下命令:

(base) C:\WINDOWS\system32>gfortran
gfortran: fatal error: no input files
compilation terminated.

因此gfortran已作为编译器安装,但是pip仍然无法安装slycot。我还安装了Microsoft Visual Studio 2017。

这时我去了PyPi库下载slycot模块的编译二进制文件。 https://www.lfd.uci.edu/~gohlke/pythonlibs/

在这里,我为系统下载了正确的.whl文件(64位Python 3.6),并使用pip进行了安装。

pip install "C:\Users\Wian\Desktop\slycot-0.3.3-cp36-cp36m-win_amd64.whl"

使用此命令slycot 0.3.3已成功安装。但是,当我运行命令

control.ss2tf(A,B,C,D)

我得到以下输出

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~\Anaconda3\lib\site-packages\control\xferfcn.py in _convertToTransferFunction(sys, **kw)
   1089             try:
-> 1090                 from slycot import tb04ad
   1091                 if len(kw):

ImportError: cannot import name 'tb04ad'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-8-2b014ac15956> in <module>()
----> 1 control.ss2tf(Model)

~\Anaconda3\lib\site-packages\control\xferfcn.py in ss2tf(*args)
   1315         sys = args[0]
   1316         if isinstance(sys, StateSpace):
-> 1317             return _convertToTransferFunction(sys)
   1318         else:
   1319             raise TypeError("ss2tf(sys): sys must be a StateSpace object.  It \

~\Anaconda3\lib\site-packages\control\xferfcn.py in _convertToTransferFunction(sys, **kw)
   1113                 # If slycot is not available, use signal.lti (SISO only)
   1114                 if (sys.inputs != 1 or sys.outputs != 1):
-> 1115                     raise TypeError("No support for MIMO without slycot")
   1116 
   1117                 # Do the conversion using sp.signal.ss2tf

TypeError: No support for MIMO without slycot

当我尝试用Python导入slycot时,得到以下结果:

>>> import slycot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Wian\Anaconda3\lib\site-packages\slycot\__init__.py", line 18, in <module>
    from .analysis import ab01nd,ab05md,ab05nd,ab07nd,ab08nd, \
  File "C:\Users\Wian\Anaconda3\lib\site-packages\slycot\analysis.py", line 21, in <module>
    from . import _wrapper
ImportError: DLL load failed: The specified module could not be found.

Slycot目录中有一个_wrapper.pyd文件(在Anaconda3 \ Libs \ site-packages下)。

这是我目前遇到的问题,无法正常导入Slycot。

非常感谢您的帮助!

0 个答案:

没有答案