为什么 virtualenv 不创建 DLLs 文件夹?

发布于 2024-11-23 15:45:43 字数 258 浏览 3 评论 0原文

我想知道 virtualenv 没有像创建 Lib 和 Scripts 文件夹一样创建 DLLs 文件夹的原因是什么?

当我在使用 PyDev 时遇到以下问题时,我就想到了这个问题;
我将我的一个 virtualenv 设置为 Python 解释器,除了一个例外,一切正常。对于来自 select 模块的所有导入,我不断收到有关未解决的导入的警告。这是因为 select 模块与大多数其他模块不同,仅存在于 DLL 文件夹中。

I'm wondering what's the reason virtualenv doesn't create DLLs folder the same way it creates Lib and Scripts ones?

The question came to me when I had the following problem with PyDev;
I set one of my virtualenvs as a Python interpreter and everything was ok with one exception. I've kept getting warnings about unresolved import for all imports from select module. This is because select module, unlike most others, is present only in the DLLs folder.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕嗳→ 2024-11-30 15:45:43

我对这个主题进行了更多研究。我从techtonik的声明开始 - 答案很简单 - 没有人实现它。然而,这又引出了另一个问题 - 为什么没有人实现它?我怀疑答案是因为它有效。这又引出了另一个问题——它为什么有效?

无需将 DLLs 文件夹复制到 virtualenv 即可一切正常的原因是,

  • 搜索 sys.path 以查找它需要 sys.path 的任何 dll
  • Python在 vi​​rtualenv 后 激活包含原始DLLs文件夹的路径

第一条语句可以通过从sys.path中删除DLLs文件夹的路径并尝试导入来简单测试select 模块(该模块需要DLLs 文件夹中的 select.pyd 文件),然后失败。

在评论中,您说我想将 Python 模块的 DLL 与 Python 代码一起保留在虚拟环境中。只需将 DLLs 文件夹复制到 virtualenv 即可实现这一点。这样做的原因是 virtualenv 激活后的 sys.path 还包含 virtualenv 内的 DLLs 文件夹的路径(尽管创建 virtualenv 时没有创建这样的文件夹)。该路径放置在原始 DLLs 文件夹的路径之前,这意味着首先搜索它,从而覆盖原始 DLLs 文件夹。

我在 Python 的邮件列表中发布了标题为 Windows 上的 DLLs 文件夹 的问题。

I investigated this subject a little more. I started from techtonik's statement - The answer is simple - nobody implemented it. This however, begs another question - why nobody implemented it? I suspect the answer is because it works. This leads to yet another question - why does it work?

The reason everything works without DLLs folder being copied into virtualenv is that

  • Python searches sys.path to find any dll it needs
  • sys.path after virtualenv's activation contains path to the original DLLs folder

The first statement can be simply tested by removing path to DLLs folder from sys.path and trying to import select module (this module needs select.pyd file from DLLs folder) which then fails.

In the comment you say I'd like to keep Python module's DLLs in the virtual environment along with the Python code. That's possible by simply copying DLLs folder into virtualenv. The reason this works is that sys.path after virtualenv's activation contains also path to the DLLs folder inside virtualenv (although there's no such folder being created when creating virtualenv). This path is placed before path to the original DLLs folder which means it's being searched first and thus overrides the original DLLs folder.

I posted question titled DLLs folder on Windows at Python's mailing list.

过去的过去 2024-11-30 15:45:43

答案很简单——没有人实施它。当我创建补丁将 pythonXX.dll 复制到 virtualenv 环境中时 - 我正在解决一个不同的问题:

当系统范围内安装 Python 时 - 复制到 virtualenv 的 python.exe 二进制文件始终能够找到其 pythonXX.dll,因为此 .dll 可从 Windows\System32 获取。如果仅为当前用户安装 Python - pythonXX.dll 将被放置到原始 python.exe 所在的 PythonXX 目录中。所以我要解决的问题是修复为当前用户安装的Python创建的virtualenvs。把这些东西挖出来是一个很大的问题。

回到问题。我真的不知道这个 pythonXX.dll 如何找到它的 DLL 模块 - 这是 Python 开发人员的问题,但我怀疑它找不到它们。我在修复 issue #87 时没有解决此问题的原因是我的代码可能从未使用过此 DLL 目录中的模块。

The answer is simple - nobody implemented it. When I created the patch to copy pythonXX.dll into virtualenv environment - I was solving a different problem:

When Python is installed system-wide - the python.exe binary that is copied to virtualenv is always able to find its pythonXX.dll, because this .dll is available from Windows\System32. If Python is installed only for current user - the pythonXX.dll is placed into PythonXX dir where original python.exe is located. So the problem I was solving is to fix virtualenvs created with Python installed for current user. It was quite a problem to dig up all this stuff.

Back to the question. I don't really know how this pythonXX.dll finds its DLLs modules - this is a question to Python developers, but I suspect that it doesn't find them. The reason why I didn't fix this issue while fixing issue #87 is that my code probably never used modules from this DLLs directory.

对岸观火 2024-11-30 15:45:43

IMO 还有更多原因:

  • 安全性:在某些环境中,策略是拒绝从随机位置执行/加载内容,以防止安全漏洞。因此,
  • 有点著名的 DLL 加载 订单,这可以防止要加载的恶意 dll :)。另请参阅此处

HTH,

IMO there are more reasons for that:

  • Security: In some environments, the policy is to deny executing/loading stuff from random locations, in an attempt to prevent security breaches. Thus,
  • The somewhat famous DLL load order, which prevents malicious dlls to be loaded :). See also here

HTH,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文