Reputation: 59
I really don't understand how batch files work. But I made a python script for my father to use in his work. And I thought installing pip and necessary modules with a single batch file would make it a lot easier for him. So how can I do it?
The modules I'm using in script are: xlrd, xlsxwriter and tkinter.
Upvotes: 4
Views: 27907
Reputation: 121
To make sure your Windows is running pip, download get-pip.py and place it in the same folder as the .bat file. You can create a .bat file using a text editor and then changing the extension to .bat
Try this:
@echo off
:start
cls
set python_ver=36
python ./get-pip.py
cd \
cd \python%python_ver%\Scripts\
pip install xlrd
pip install XlsxWriter
pause
exit
tkinter in already included in Python since 3.1
Upvotes: 8
Reputation: 60
You can create a requirements.txt
file then use pip install -r requirements.txt
to download all modules, if you are working on a virtual environment and you only have the modules your project uses, you can use pip3 freeze >> requirements.txt
This is not a batch file but it will work just fine and it is pretty easy
Upvotes: 4
Reputation: 1182
To install pip, you can download get-pip.py and run it like that in your batch file (batch file and get-pip.py should be in the same folder) :
python get-pip.py
Then to install modules, you can create a file requirements.txt (in the same folder) with this content :
xlrd
xlsxwriter
tkinter
and use this command in your batch file :
pip install -r requirements.txt
The problem is that now you have 3 files, get-pip.py, requirements.txt and the batch file. If you want to make it easier, you can hide the py & txt file in the properties like that (for Windows) :
Or you can get rid of requirements.txt by replacing
pip install -r requirements.txt
with
pip install xlrd
pip install xlsxwriter
pip install tkinter
in your batch file.
Upvotes: 2
Reputation: 1020
I think the route you are taking is hard and may create a lot of difficulty for the non-technical person. My advice would be to to consider these alternatives:
I used to create scripts as a freelancer and my life became easier when I learned to distribute them using those 2 methods.
Upvotes: 4