首页 > 编程问答 >尝试使用 pyinstaller 将 python 文件转换为可执行文件时出现 TypeError

尝试使用 pyinstaller 将 python 文件转换为可执行文件时出现 TypeError

时间:2024-07-24 05:59:12浏览次数:11  
标签:python pyinstaller

稍后的目的是通过命令行向 GPT4all 发送问题并将答案存储在文本文档中。 我想将阻止代码转换为 exe,但它产生了 TypeError。

这是到目前为止的代码:

from gpt4all import GPT4All

model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf", device='cpu')  # downloads / loads a 4.66GB LLM
with model.chat_session():
    with open("C:\\Temp\\Antwort.txt", "a") as a:
        print(model.generate("What is the capital of France?", max_tokens=1024), file=a)

这就是错误:

(.venv) PS C:\Users\lbuntenbach\PycharmProjects\GPT4all> pyinstaller --onefile Learning.py
1048 INFO: PyInstaller: 6.9.0, contrib hooks: 2024.7
1048 INFO: Python: 3.12.4
1115 INFO: Platform: Windows-10-10.0.19045-SP0
1115 INFO: Python environment: C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv
1131 INFO: wrote C:\Users\lbuntenbach\PycharmProjects\GPT4all\Learning.spec
1147 INFO: Module search paths (PYTHONPATH):
['C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Scripts\\pyinstaller.exe',
 'C:\\Users\\lbuntenbach\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip',
 'C:\\Users\\lbuntenbach\\AppData\\Local\\Programs\\Python\\Python312\\DLLs',
 'C:\\Users\\lbuntenbach\\AppData\\Local\\Programs\\Python\\Python312\\Lib',
 'C:\\Users\\lbuntenbach\\AppData\\Local\\Programs\\Python\\Python312',
 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv',
 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages',
 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\setuptools\\_vendor',
 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all']
2100 INFO: checking Analysis
2100 INFO: Building Analysis because Analysis-00.toc is non existent
2100 INFO: Running Analysis Analysis-00.toc
2100 INFO: Target bytecode optimization level: 0
2100 INFO: Initializing module dependency graph...
2119 INFO: Caching module graph hooks...
2190 INFO: Analyzing base_library.zip ...
7332 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
9867 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
12568 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
16389 INFO: Caching module dependency graph...
16721 INFO: Looking for Python shared library...
16754 INFO: Using Python shared library: C:\Users\lbuntenbach\AppData\Local\Programs\Python\Python312\python312.dll
16754 INFO: Analyzing C:\Users\lbuntenbach\PycharmProjects\GPT4all\Learning.py
16918 INFO: Loading module hook 'hook-platform.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
19333 INFO: Loading module hook 'hook-charset_normalizer.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
19724 INFO: Loading module hook 'hook-certifi.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
20570 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
20768 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
21469 INFO: Loading module hook 'hook-importlib_resources.py' from 'C:\\Users\\lbuntenbach\\PycharmProjects\\GPT4all\\.venv\\Lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\__main__.py", line 231, in _console_script_run
    run()
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\__main__.py", line 215, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\__main__.py", line 70, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\building\build_main.py", line 1216, in main
    build(specfile, distpath, workpath, clean_build)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\building\build_main.py", line 1156, in build
    exec(code, spec_namespace)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\Learning.spec", line 4, in <module>
    a = Analysis(
        ^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\building\build_main.py", line 556, in __init__
    self.__postinit__()
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
    self.assemble()
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\building\build_main.py", line 696, in assemble
    program_scripts.append(self.graph.add_script(script))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 268, in add_script
    self._top_script_node = super().add_script(pathname)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1160, in add_script
    self._process_imports(n)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 368, in _safe_import_hook
    excluded_imports = self._find_all_excluded_imports(source_module.identifier)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\analysis.py", line 356, in _find_all_excluded_imports
    excluded_imports.update(module_hook.excludedimports)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\imphook.py", line 316, in __getattr__
    self._load_hook_module()
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\depend\imphook.py", line 383, in _load_hook_module
    self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\compat.py", line 583, in importlib_load_source
    mod_loader.exec_module(mod)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks\hook-importlib_resources.py", line 18, in <module>
    if check_requirement("importlib_resources < 1.2.0"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 414, in check_requirement
    return parsed_requirement.specifier.contains(version, prereleases=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\packaging\specifiers.py", line 906, in contains
    item = Version(item)
           ^^^^^^^^^^^^^
  File "C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\packaging\version.py", line 200, in __init__
    match = self._regex.search(version)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

到目前为止,返回似乎是 None,但是我无法理解是什么产生了 None 值。 有人可以解释 None 值的起源吗?有没有办法解决这个问题? 我是 Python 新手,感谢每一条建议。


这个错误与 gpt4all 库本身有关,而非你的代码。看起来像是 PyInstaller 试图分析你的依赖,并在 importlib_resources 的版本检查中遇到了问题。

你可以尝试以下步骤来解决此问题:

1. 更新相关库

首先,确保你使用的库都是最新版本。这可能修复版本冲突或已知错误。

pip install --upgrade pyinstaller packaging importlib_resources gpt4all

2. 指定 importlib_resources 版本

如果更新后问题仍然存在,尝试在你的代码中明确指定 importlib_resources 版本。这可以帮助 PyInstaller 正确分析依赖关系。

在你的脚本顶部添加以下内容:

import importlib.metadata
try:
    version = importlib.metadata.version('importlib_resources')
except importlib.metadata.PackageNotFoundError:
    # Package is not installed.
    version = None

if version is not None and version.startswith("5."):
    import importlib_resources
else:
    import importlib_resources as pkg_resources 

然后,在你的代码中,将所有对 importlib_resources 的引用替换为 pkg_resources

3. 使用 --hidden-import 参数

如果以上方法都无法解决问题,你可以尝试使用 PyInstaller 的 --hidden-import 参数手动指定 importlib_resources

pyinstaller --onefile --hidden-import=importlib_resources Learning.py

4. 使用虚拟环境

为了避免依赖冲突,建议在虚拟环境中运行你的项目。

python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt  # 安装项目依赖
pyinstaller --onefile Learning.py

5. 报告问题

如果问题仍然存在,请在 PyInstaller 或 gpt4all 的 GitHub 存储库中提交问题,并提供详细的错误信息和你的环境配置。这可以帮助开发者识别并修复问题。

请注意, gpt4all 库的开发非常活跃,可能存在一些尚未解决的兼容性问题。如果以上方法都无法解决问题,你可以考虑使用其他 GPT-4 库或等待 gpt4all 发布更新版本。

标签:python,pyinstaller
From: 78764858

相关文章

  • 使用 Python-PlexAPI 获取 plex 上所有好友的关注列表
    有关如何接收我的plex服务器上所有用户的监视列表的任何提示。我正在根据一些规则创建自动删除,其中一个规则是,如果电影位于用户观看列表中,则不应删除该电影。我遇到了麻烦,因为所有与观看列表相关的内容都在MyPlexAccount上。lexapi.myplex.MyPlexAccount具有我的用......
  • 如何在 Python 中查看与 Azure OpenAI 助手关联的所有上传文件?
    我正在使用Python对文档中的问题进行基准测试,并在jupyter笔记本中实例化了我的助手。我想确认助手是否有我上传的文件,但似乎找不到有关此功能将使用什么功能的文档。使用适用于AzureOpenAI的最新版本的PythonAPI。目前,无法使用AzureOpenAI的PythonAPI直接查看......
  • 如何在Python中计算小数?
    我正在创建一个计算器来用python计算企业的利润,但到目前为止我只能使用整数。这是我的代码示例:Gross=int(input("PleaseentertotalGrossRevenuefortheFiscalYear"))NetTaxes=int(Gross)*0.1所以我将会计年度的总收入乘以按“税率”计算,但我只能使用......
  • 如何使用 Python 打开 Google Firestore 上的特定数据库?
    我正在使用Firebase并使用以下代码从Firestore设置/检索文档:importfirebase_adminfromfirebase_adminimportcredentials,firestorecred=credentials.ApplicationDefault()firebase_admin.initialize_app(cred,options={"projectId":"huq-jimbo"})fires......
  • 如何使用 Python 和 Numpy 重现 Matlab 文件读取以解码 .dat 文件?
    我有一个Matlab脚本,可以读取编码的.dat文件,对其进行解码并保存。我试图使用numpy将其转换为Python。我发现对于同一个文件,我得到不同的输出结果(python数字没有意义)。该代码最初作为从串行端口读取的脚本的一部分运行,因此是数据的结构。我首先认为位移是问题所在,因为......
  • 在Python中调整pdf页面大小
    我正在使用python裁剪pdf页面。一切正常,但如何更改页面大小(宽度)?这是我的裁剪代码:input=PdfFileReader(file('my.pdf','rb'))p=input.getPage(1)(w,h)=p.mediaBox.upperRightp.mediaBox.upperRight=(w/4,h)output.addPage(p)当我裁剪页面时,我也需要......
  • 如何使用 python 更改资源管理器窗口中的路径?
    没有人知道如何在不使用python打开新实例的情况下更改资源管理器窗口中的当前路径吗?例如,如果用户使用C:\Users\User打开资源管理器窗口。然后我必须将该路径更改为C:\Windows\System32例如。提前致谢。很遗憾,无法直接使用Python更改现有文件资源管理器窗口的......
  • python 以及将数组传递给函数的问题
    我需要求解一些常微分方程$\frac{dy}{dx}=f(x)=x^2ln(x)$并继续在限制0之间创建数组xpt。<=xpt<=2因为我必须小心xpt=0,所以我将函数定义如下deff(x):ifx<=1.e-6:return0.else:returnnp.square(x)*np.log(x)我的调用程序读取Np......
  • 如果 Python 脚本正在使用文件夹,如何在文件资源管理器中进行更改时防止 Windows 的“
    我有一个简单的脚本,显示在QTreeView中的QListView中选择的目录的内容,我想添加打开文件资源管理器的功能,以让用户编辑目录内的内容。但是,添加新的文件夹和文件可以,但删除或移动文件夹或文件会提示“文件夹正在使用”错误:此操作无法完成,因为该文件已在另一个程......
  • 如何使用 Python API 获取每个模型的活跃用户列表、最后登录信息
    我想通过PythonAPI获取我的dbt项目的所有模型中的活动或非活动用户列表。这可能吗?我尝试列出模型,但无法获取用户信息,如用户名、项目、以及上次活动或上次登录。不幸的是,dbt本身并不跟踪你所寻找的用户活动数据(最后登录、活跃用户等)。dbt的主要功能是转换数据,而不......