如果您正在联系支持人员解决 Python Moku API 问题,请复制此脚本并从您通常运行 Python 脚本的地方运行它,无论是命令提示符、终端、Visual Studio、Spyder、Jupyter Notebook、Anaconda 等。
import os
import subprocess
import sys
import re
print("\n")
python_path = sys.executable
python_ver = subprocess.check_output([python_path, "--version"])
python_ver = re.search(r"(\d+\.)+\d+", str(python_ver))[0]
moku_link = "https://apis.liquidinstruments.com/starting-python.html"
cli_link = "https://liquidinstruments.com/software/utilities/"
target_link = "https://apis.liquidinstruments.com/cli/moku-cli.html"
target_link += "#finding-the-target-path-python"
try:
from moku import __version__
except ImportError as e:
if str(e) == "No module named 'moku'" or str(e) == "No module named moku":
print("%s\nPLEASE RUN `pip install moku`" % e)
moku_ver = "Moku module not found `pip install moku` %s" % moku_link
elif (str(e) == "No module named 'pkg_resources'" or
str(e) == "No module named pkg_resources"):
print("%s\nPLEASE RUN `pip install setuptools`" % e)
moku_ver = "pkg_resources module not found `pip install setuptools`"
elif str(e).startswith("cannot import name '__version__' from 'moku'"):
try:
pip_moku = subprocess.check_output([python_path, "-m",
"pip", "show", "moku"])
moku_ver = re.search(r"(\d+\.)+\d+", str(pip_moku))[0]
except Exception as e:
print(e)
moku_ver = "Unknown error"
else:
print(e)
moku_ver = "Unknown error"
else:
moku_ver = __version__
moku_ver = re.search(r"(\d+\.)+\d+", str(moku_ver))[0]
try:
from moku import MOKU_DATA_PATH
except ImportError as e:
if str(e) == "No module named 'moku'" or str(e) == "No module named moku":
print("%s\nPLEASE RUN `pip install moku`" % e)
moku_path = "Moku module not found"
moku_fw = "Moku module not found"
elif (str(e) == "No module named 'pkg_resources'" or
str(e) == "No module named pkg_resources"):
print("%s\nPLEASE RUN `pip install setuptools`" % e)
moku_path = "pkg_resources module not found"
moku_fw = "pkg_resources module not found"
else:
print(e)
moku_path = "Unknown error"
moku_fw = "Unknown error"
else:
moku_path = MOKU_DATA_PATH
try:
moku_fw = os.listdir(MOKU_DATA_PATH)
except FileNotFoundError as e:
print("\nmoku data error: %s\n" % e)
print("PLEASE RUN\nmkdir %s" % MOKU_DATA_PATH)
print("mokucli download ### --target=%s" % MOKU_DATA_PATH)
print(" (where ### is the FW_VER)")
moku_fw = "Data folder doesn't exist: %s" % target_link
else:
if moku_fw == []:
print("\nPLEASE RUN")
print("mokucli download ### --target=%s" % MOKU_DATA_PATH)
print(" (where ### is the FW_VER)")
moku_fw = "Data files not downloaded: %s" % target_link
try:
from moku import MOKU_CLI_PATH
except ImportError as e:
if str(e) == "No module named 'moku'" or str(e) == "No module named moku":
cli_path = "Moku module not found"
cli_ver = "Moku module not found `pip install moku` %s" % moku_link
elif (str(e) == "No module named 'pkg_resources'" or
str(e) == "No module named pkg_resources"):
cli_path = "pkg_resources module not found"
cli_ver = "pkg_resources module not found `pip install setuptools`"
else:
print(e)
cli_path = "Unknown error"
cli_ver = "Unknown error"
else:
cli_path = MOKU_CLI_PATH
try:
cli_ver = subprocess.check_output([MOKU_CLI_PATH, "--version"])
cli_ver = re.search(r"(\d+\.)+\d+", str(cli_ver))[0]
except Exception as e:
print("mokucli error: %s\nPLEASE INSTALL MOKUCLI %s" % (e, cli_link))
cli_ver = "Couldn't call mokucli, install from %s" % cli_link
print("\n")
print("PYTHON PATH: %s" % python_path)
print("PYTHON VERSION: %s" % python_ver)
print("MOKUCLI PATH: %s" % cli_path)
print("MOKUCLI VERSION:%s" % cli_ver)
print("MOKU DATA PATH: %s" % moku_path)
print("MOKU VERSION: %s" % moku_ver)
print("MOKU DATA FW: %s" % moku_fw)
这将输出一些文本,您可以复制并发送回我们的支持工程师,它看起来像这样:
PYTHON PATH: c:\Users\user\AppData\Local\Programs\Python\Python312\python.exe
PYTHON VERSION: 3.12.3
MOKUCLI PATH: C:\Program Files\Liquid\Moku CLI\mokucli.EXE
MOKUCLI VERSION:2.3.0
MOKU DATA PATH: c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\moku\data
MOKU VERSION: 3.3.3
MOKU DATA FW: ['mokudata-601.tar']
如果此脚本返回:
[WinError 3] The system cannot find the path specified: ...
[Errno 2] No such file or directory: ...
这意味着 moku 目录中没有数据文件夹。请按照说明在 moku 安装中创建数据文件夹,然后下载数据文件(比特流):
这些说明也将在脚本输出中给出,请仔细阅读并遵循给出的任何说明。
如果这些步骤不能解决问题,您可以在此处下载比特流,然后使用 Finder 或文件资源管理器手动创建文件夹并复制比特流。