首页 > 解决方案 > 用于 OSX Swift 项目的 PythonKit 突然找不到模块

问题描述

我使用 PythonKit 构建了一个 MacOS 应用程序来运行一些脚本并返回数据。前几天我让它运行没有问题,但现在尝试加载脚本文件时它崩溃了。我已经验证文件的路径是正确的,并且在终端中运行 Python 脚本没有任何问题。

这是错误消息:

Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'helloswift': file PythonKit/Python.swift, line 674
2021-04-09 10:01:55.441796-0400 TechCommToolKit[10754:2952424] Fatal error: 'try!' expression unexpectedly raised an error: Python exception: No module named 'helloswift': file PythonKit/Python.swift, line 674

PythonKit 中抛出它的代码行:

public func `import`(_ name: String) -> PythonObject { return try! attemptImport(name) }

我在文件中的 Python 代码:

import requests
import json
import sys

def getConfluenceData(strEndPoint):

    s = requests.Session()

    response = s.post('https://wiki.xxxx.com/dologin.action', data={'os_username': 'app_wiki_api2', 'os_password': 'xxxxxxxxxxxxxxxx'})
    response = s.get(strEndPoint)

    json_formatted_str = json.dumps(response.json(), indent=4)

    return(json_formatted_str)

标签: pythonswiftmacos

解决方案


呃,这是操作员错误,我指向的是文件,而不是包含文件的目录。


推荐阅读