gpt4 book ai didi

python - 如何在 blender 中安装python模块

转载 作者:太空狗 更新时间:2023-10-30 00:08:03 31 4
gpt4 key购买 nike

我一直在尝试为 blender 安装 pyserial,但我只能将它安装到我的 C 驱动器上的 python32,我能做些什么来将它安装到 blender 或从 python32 导入 blender

最佳答案

对于 Windows,没有特殊权限,并且仅来自 blender python 脚本:

  1. 从 blender 脚本安装你想要的包(tqdm 下面给出的例子):

    import pip
    pip.main(['install', 'tqdm', '--user'])
  2. 从 blender 控制台观察 pip 在您的配置中实际安装包的路径 (WARNING: The script tqdm.exe is installed in 'C:\Users\<Username>\AppData\Roaming\Python\Python39\Scripts' which is not on PATH):

    Blender console, actial installing package location

  3. 在 blender 脚本中,将你的 blender 的 pip 安装包的路径添加到 PATH :

    import sys
    packages_path = "C:\\Users\\<Username>\\AppData\\Roaming\\Python\\Python39\\Scripts" + "\\..\\site-packages"
    sys.path.insert(0, packages_path )
  4. 在脚本中成功导入您的包:

    import tqdm

更新1

要在 v2.93 中显示 Blender 终端,请单击 Window -> Toggle System Console

enter image description here

更新2

整个脚本

# 1. launch next 2 lines of code in blender python interpreter

import pip
pip.main(['install', 'tqdm', '--user'])

import sys

# 2. watch blender's python path in console output at this moment
# 3. insert the path to packages_path below and uncomment

# packages_path = "C:\\Users\\<Username>\\AppData\\Roaming\\Python\\Python39\\Scripts" + "\\..\\site-packages" # the path you see in console

# 4. uncomment the next code and launch script in blender interpreter again

# sys.path.insert(0, packages_path )
# import tqdm

# use installed packages here

关于python - 如何在 blender 中安装python模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11161901/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com