简体   繁体   English

是否可以在没有安装的情况下运行Python(不使用像py2exe这样的包装器)?

[英]Is it possible to run Python without installation (without using packagers like py2exe)?

We have a complex tool (coded in Python) for environment validation and configuration. 我们有一个复杂的工具(用Python编码),用于环境验证和配置。 It runs on various Windows flavors. 它运行在各种Windows风格上。 We used this tool within the company so far. 到目前为止,我们在公司内使用了这个工具。 However now we want our support engineers to use it on the road. 但是现在我们希望我们的支持工程师在路上使用它。 The problem is they will not have permissions to install Python in customer machines. 问题是他们没有权限在客户机器上安装Python。

To address this situation, we looked at utilities like py2exe, cx_freeze and pyInstaller. 为了解决这种情况,我们研究了py2exe,cx_freeze和pyInstaller等实用程序。 While they are good, the generated EXE runs into dependency issues in some situations. 虽然它们很好,但生成的EXE会在某些情况下遇到依赖性问题。 So we dropped using these tools. 所以我们放弃使用这些工具。

Is it possible to take all python related files in a pen drive and run it directly from it? 是否可以将所有与python相关的文件放在笔式驱动器中并直接从它运行? When we do that, obviously the interpreter complains because the DLLs are not registered on the target machine. 当我们这样做时,显然解释器会抱怨,因为DLL没有在目标机器上注册。 I suspect just registering the DLLs may lead to other problems. 我怀疑只是注册DLL可能会导致其他问题。 Is there a simple solution to this? 有一个简单的解决方案吗?

Suppose your script is main.py , 假设你的脚本是main.py

  • copy all the contents of python directory to the directory it reside in 将python目录的所有内容复制到它所在的目录中
  • search python*.dll in your windows directory and it to project/python 在你的windows目录中搜索python*.dll ,然后搜索到project/python
  • create project/main.bat : create project/main.bat

main.bat main.bat

"%~dp0/python/python.exe" "%~dp0/main.py" %*

The project directory should be: 项目目录应该是:

project
├── python
|   ├── python.exe
|   ├── python27.dll
|   └── ...
├── main.py
└── main.bat

Now, invoke the program with main.bat 现在,使用main.bat调用该程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM