gpt4 book ai didi

Python - libs 子文件夹的用途是什么?

转载 作者:太空狗 更新时间:2023-10-30 00:07:28 25 4
gpt4 key购买 nike

对我来说,它位于 C:\Python33\libs。

供引用 - 这与 C:\Python33\Lib 相同的文件夹 - 请注意大写和缺少“s”。

在我工作的一台计算机上,我只是将一个 .py 文件放到 libs 文件夹中,然后可以像库/模块一样导入和使用它(抱歉,我不太了解术语),无论在哪里我正在从事的项目是。

但是,在尝试在另一台机器上复制它时,这是行不通的。尝试导入只会给出“没有名为 X 的模块”错误。

所以,很明显我误解了 libs 文件夹的用途,以及它与 Lib 文件夹的区别。

那么, 到底有什么区别?

最佳答案

如果比较 libs/和 Lib/,您会发现后者充满了 *.py 文件,而前者只有 *.lib 文件。使用文本编辑器的进一步调查将显示 *.py 文件是人类可读的(我希望如此)而 *.lib 文件不是。

这就是真正的区别。如果您想了解更多,.lib 文件是静态链接库,用于构建 .dll、C 扩展以及所有这些好东西。往下走rabbit hole如果您对此感兴趣。

关于您的问题的核心:您是否应该能够将模块放入其中并能够导入它们?并不真地。这是该文件夹包含在您的路径中的副作用。来自模块 docs :

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

  • the directory containing the input script (or the current directory).
  • PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
  • the installation-dependent default.

各种安装方法都会修改%PATH% 或%PYTHONPATH% 所以我不能告诉你具体在哪里看;在我的 Windows 机器上,python 安装程序为我修改了 %PATH%,所以你应该先看看那里。值得注意的是,我的路径包括 Python33/libs/,所以我不希望它默认存在。

关于Python - libs 子文件夹的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19285892/

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