如何在别人的 Windows 机器上的虚拟环境中本地运行 python 脚本并使其始终如一地工作? [英] How to run a python script locally in a virtual environment on someone elses windows machine and have it consistently work?

查看:41
本文介绍了如何在别人的 Windows 机器上的虚拟环境中本地运行 python 脚本并使其始终如一地工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为同事制作脚本/工具,希望他们可以通过共享驱动器在他们的 Windows 机器上使用这些脚本/工具.Python 版本和库当然是不一致的,尝试这样做是一团糟.他们只是希望它单击运行并且它可以工作,如果他们必须使用命令行或 pip,这只是意味着他们不会使用该工具.

I'm making scripts/tools for colleagues that they can hopefully on their windows machines from a shared drive. Python versions and libraries are not consistent of course, and it's a mess to try do this. They just want it click run and it works, if they have to use the command line or pip, it just means they won't use the tool.

我开始在 Pycharm 中使用虚拟环境制作我的项目,这似乎是前进的方向.但是,我对他们很陌生,我很难找到有关如何完成流程的信息.也许我使用了错误的搜索关键字,我一直在寻找最后一步的指南.

I started making my projects with virtual environments in Pycharm and that seems the way forward. But, I'm very new to them and I'm having trouble finding info about how to finalize the process. Maybe I'm using the wrong search keywords, I've been looking for a guide for this final step.

我在想我可以复制 venv 文件夹并制作一个批处理文件来运行本地 python.exe(run.bat 文件):

I was thinking I could copy venv folders over and make a batch file to run the local python.exe (run.bat file):

venvScriptspython.exe script.py

但是还有额外的不需要的库.为了使其精简,我是否要一一卸载它们?这个接受的答案复制并粘贴venv,这让我有点困惑.

But then there are extra unneeded libraries. To make it lean do I uninstall them one by one? This accepted answer says not to copy and paste the venv over, which has me a little confused.

所以我应该冻结 requirements.txt 然后让我的 run.bat 也安装库吗?这对我来说似乎更混乱.

So I should freeze requirements.txt and then have my run.bat also install the libraries? This seems more messy to me.

什么是约定?对于这种情况,最好的选择是什么?

What's the convention? And what's the best option for this situation?

干杯.

推荐答案

你可以用 pyinstaller.这需要你做一些额外的工作,但你最终会得到一个独立的可执行文件,包括正确的 python 解释器和依赖项.

You could package your tools with pyinstaller. It would require some extra work on your end, but you would end-up with a stand alone executable including the correct python interpreter and dependencies.

这篇关于如何在别人的 Windows 机器上的虚拟环境中本地运行 python 脚本并使其始终如一地工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆