1

seabreeze ( seabreeze ) と pyseabreeze ( pyseabreeze )を使用して、Ocean optics 分光計と接続しようとしています。

Windows のコマンド プロンプト (cmd) から python と入力し、次のコードを 1 行ずつ入力すると動作します。しかし、それをスクリプト(spec_test.py)に入れて、「python spec_test.py」を使ってcmd.exeから実行しようとすると、うまくいきません。

私は同様の問題をたくさん検索しましたが、私が抱えている問題をカバーしているようには見えません。anacondaを使用してインストールされたWindows 7 64ビット、python 3.5.2を実行しています。pyseabreeze を使用するには、pyusb と libusb もインストールする必要がありました。

コード:

import seabreeze
seabreeze.use('pyseabreeze')
import seabreeze.spectrometers as sb

devs = sb.list_devices()
print(devs)
spec = sb.Spectrometer(devs[0])
print(spec.model)

そして私が得るエラーメッセージ:

[<SeaBreezeDevice USB2000PLUS:FLMS02379>]
Traceback (most recent call last):
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\common.py", line 14, in decorated_func
    return func(*args, **kwargs)
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\spectrometer.py", line 46, in open
    self.open_device(device.handle)
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\communication.py", line 37, in open_device
    device.set_configuration()
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\core.py", line 869, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\core.py", line 148, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\backend\libusb0.py", line 493, in set_configuration
    _check(_lib.usb_set_configuration(dev_handle, config_value))
  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\usb\backend\libusb0.py", line 431, in _check
    raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'libusb0-dll:err [set_configuration] could not set config 1: win error: The parameter is incorrect.\r\n'
Traceback (most recent call last):

  File "<ipython-input-9-ead886eb3666>", line 1, in <module>
    runfile('C:/Users/Raman Lab/Python code/Spectrometers/spec_testing.py', wdir='C:/Users/Raman Lab/Python code/Spectrometers')

  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Raman Lab/Python code/Spectrometers/spec_testing.py", line 7, in <module>
    spec = sb.Spectrometer(devs[0])

  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\spectrometers.py", line 62, in __init__
    self._open_device(device)

  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\spectrometers.py", line 90, in _open_device
    lib.device_open(self._dev)

  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\wrapper.py", line 81, in device_open
    return device.interface.open(device)

  File "C:\Users\Raman Lab\AppData\Local\Continuum\Anaconda3\lib\site-packages\seabreeze\pyseabreeze\interfaces\common.py", line 23, in decorated_func
    raise SeaBreezeError(msg)

SeaBreezeError: An error occured during opening.

助けてくれてありがとう!

編集:何らかの理由で私はこれを理解し、問題を説明するのに役立つかもしれないと考えました. cmd.exe からインタラクティブ python に入り、手動で入力する代わりにコードを貼り付けると、同じエラーが発生します。これは、インポートの速度と何らかの形で結びついていると私に思わせます (ほとんどの場合、私は間違っています)。プロンプトを入力しているときに何が起こるかをシミュレートするために、3 行目と 5 行目の間に数秒間スリープを追加しようとしましたが、それは役に立ちませんでした。これで十分に説明できたことを願っています。

4

1 に答える 1