1

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.

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.

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

venv\Scripts\python.exe script.py

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.

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?

Cheers.

Declan
  • 574
  • 4
  • 15
  • You can probably check more common ways to make python program distributable: https://stackoverflow.com/questions/24783462/is-it-possible-to-create-a-python-program-distributable-for-windows-that-can-be – Slowpoke Oct 18 '18 at 18:03
  • Possible duplicate of [Why virtualenv relies on the global python instead of the local one, after being pulled?](https://stackoverflow.com/questions/52856436/why-virtualenv-relies-on-the-global-python-instead-of-the-local-one-after-being) – phd Oct 18 '18 at 20:49
  • Try with the accepted answer from this [question](https://stackoverflow.com/questions/14684968/how-to-export-virtualenv); Works for me. – ToCarbajal Nov 27 '19 at 22:59

1 Answers1

2

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.

iodbh
  • 688
  • 1
  • 7
  • 14
  • That sounds great. Should I install pyinstaller locally in my virtual-enviroment terminal in Pycharm for it to work? Or should install it to my normal python distribution (the one in PATH)? – Declan Oct 18 '18 at 18:18
  • pyinstaller only works if the project you're packaging uses the same python version, so installing it in your virtual environment makes sense. – iodbh Oct 19 '18 at 07:13