0

I'm distributing some python code to inexperienced users who are timid with anything involving command lines. They're okay installing Anaconda and opening Jupyter notebooks, but other than that they've never interacted with Python.

So I went googling around for an easier interface (perhaps GUI) for such a user to be able install local Python packages or Python wheels. I stumbled across the promising-looking pip-gui (https://github.com/GDGVIT/pip-gui), but as of yet it does not install local packages, and would of course require its own installation.

So for Windows users at least I've come across the following solution (based on a script I found online that I can no longer remember). It is a powershell script that uses Windows forms to let the user select a ".whl" file and then install it with pip. It assumes the user has anaconda installed in the default directory (might need some flexibility there).

I have to distribute it as a ".txt" and ask the user to rename to ".ps1" then right click and run with powershell. That's a bit cumbersome, but users seem to be able to do that even if they aren't comfortable using "cd" and "pip" in the cmd shell.

That's the best solution I've got, and I was wondering if maybe there's something simple that I've overlooked.

Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = pwd
$f.Filter = "Python Wheel Files (*.whl)|*.whl"
$f.ShowHelp = $true
$f.Multiselect = $false
[void]$f.ShowDialog()

(& ($($Env:HOMEDRIVE)+$($Env:HOMEPATH)+"\anaconda3\Scripts\conda.exe") "shell.powershell" "hook") | Out-String | Invoke-Expression

pip install $f.FileName

Read-Host -Prompt "Press any key to continue"
William
  • 381
  • 1
  • 8

1 Answers1

2

If it's windows you can save the pip command in a .cmd file, which when clicked will automatically opens a command prompt window and runs the pip install command.

For example, save pip install <package(s)> & pause in a file named setup.cmd on your desktop and double click it.

enter image description here

enter image description here

enter image description here

pip install <package(s)> & pause

pause will give you the opportunity to ask the user for a key stoke to before it exits the command prompt windows.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Kumar Shivam Ray
  • 337
  • 2
  • 10
  • Thank you for your comment! One thing I was not clear about in my post was that the ".whl" file I want to install is one that I give to them. So they need to install a local ".whl" file (not from pypi). – William Apr 09 '21 at 23:04
  • pip install some-package.whl & pause, some-package.whl is the complete path of your .whl file. Refer to this stack overflow question: https://stackoverflow.com/questions/27885397/how-do-i-install-a-python-package-with-a-whl-file – Kumar Shivam Ray Apr 10 '21 at 08:57
  • Yes that works if you already know the path of the .whl file. In my case, my users will be downloading the .whl file so I won't know the complete path. That is why I went for a simple gui option that allows the user to select the file. – William Apr 10 '21 at 14:28
  • Right, but you user will know where they have downloaded the file. – Kumar Shivam Ray Sep 20 '21 at 02:31