在Win32上不使用安装程序的情况下安装Python

在Win32上不使用安装程序的情况下安装Python

本文介绍了在Win32上不使用安装程序的情况下安装Python 2.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在未安装Python的计算机上运行Python脚本.我将Python用作软件包的一部分,并且Python在幕后运行,而用户并未注意到.

I need to run a Python script on a machine that doesn't have Python installed. I use Python as a part of a software package, and Python runs behind the curtain without the user's notice of it.

我所做的如下.

  1. 复制python.exe,python26.dll,msvcr90.dll和Microsoft.VC90.CRT.manifest
  2. 将LIBs目录中的所有目录压缩为python26.zip
  3. 将所有必要的dll/pyd文件复制到DLL目录中.

这似乎可行,但是当我将python26.zip更改为pythonlib.zip之类的其他名称时,它再也找不到了Python库.

It seems to work, but when I change the python26.zip to the other name such as pythonlib.zip, it cannot find the Python library any more.

  • 问题1:python26.zip名称背后的魔力是什么? Python会自动在python26.zip中找到一个库,但是名称不同吗?
  • 问题2:如果我在python.exe/python26.dll所在的目录中有python26.zip,则无需添加路径sys.path.append(通往python26.zip的路径).正确吗?
  • Question 1: What's the magic behind the python26.zip name? Python automatically finds a library inside a python26.zip, but not with different name?
  • Question 2: If I have python26.zip at the same directory where python.exe/python26.dll is, I don't need to add path sys.path.append (THE PATH TO python26.zip). Is it correct?

Python具有内置库,sys是其中之一.我以为我可以使用sys.path指向我需要的ZIP文件中的任何Python库.但是,令人惊讶的是,如果我使用库名Python26.zip,它就可以正常工作.为什么会这样?

Python has built-in libraries, and sys is one of them. I thought that I could use sys.path to point to whatever Python library in the ZIP file I needed. But, surprisingly, if I use the library name as Python26.zip, it just worked. Why is this so?

推荐答案

我研究了Python解释器的源代码,并做了一些实验.而且我发现Python解释器无论如何都以"PYTHONXXX.DLL + pythonXXX.zip的目录"开头. XXX是Python解释器的版本.

I looked into the Python interpreter source code, and I did some experiments. And I found that the Python interpreter prepend the "THE DIRECTORY OF PYTHONXXX.DLL + pythonXXX.zip" no matter what. XXX is the version of the Python interpreter.

因此,如果在与python26.dll相同的目录中存在python26.zip.我可以自动使用所有Python库.

As a result, if there is a python26.zip in the same directory as the python26.dll. I could use all of the Python library automatically.

这篇关于在Win32上不使用安装程序的情况下安装Python 2.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:13