How to run a python script locally in a virtual environment on someone elses windows machine and have it consistently work?(如何在别人的 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 脚本并使其始终如一地工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在别人的 Windows 机器上的虚拟环境中本地运
基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01