gpt4 book ai didi

python - 从文件夹导入 Python 插件

转载 作者:太空宇宙 更新时间:2023-11-04 03:10:28 24 4
gpt4 key购买 nike

我想在服务器上放置一个带有模块脚本 PIL 的 python 脚本。服务器可能没有安装 PIL。 (这就是我要自己加载文件的原因)

如果可能,我怎样才能让 python 脚本从脚本的当前目录导入图像库,而无需在机器上安装它?


使用python虚拟机我在本地使用 python v2.7,就像在服务器上一样。

最佳答案

一种选择是从相对路径导入模块,如 here 所述.

也可以使用虚拟环境,您可以在其中打包所需的一切,并且不会弄乱服务器上的 python 安装。看吧herehere

其他引用:

  1. Loading all modules in a folder in Python
  2. How to do relative imports in Python?

关于python - 从文件夹导入 Python 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38187037/

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