0

I want to download files from requirement.txt file, but I need manually edit directory where I need to download them.

For example usual pip download:

!pip download -r C:/Users/Test/requirements.txt -d C:/Users/Test/whldir

But I want put it to function where will be variables for directories:

reqs = C:/Users/Test/requirements.txt
whls = C:/Users/Test/whldir
!pip download -r reqs -d whls 

Is this possible to do?

phd
  • 82,685
  • 13
  • 120
  • 165
FeoJun
  • 103
  • 1
  • 14
  • download from a Python script? just use string formatting and `subprocess.Popen` (or just the latter, it will concatenate it for you), so like `subprocess.Popen(["pip", "download", "-r", reqs, "-d", whls])` (not sure about any extra arguments but this should work... I think) – Matiiss Jul 20 '22 at 07:50
  • @Matiiss The syntax `!pip` suggests the environment is Jupyter Notebook; the OP should have mentioned that and used proper tags. – phd Jul 20 '22 at 07:59
  • @phd I was wondering what it was for, thanks for explaining... welp, haven't used Jupyter, not sure whether my comment is needed anymore then – Matiiss Jul 20 '22 at 08:02
  • `pip` itself has no such facility, but the environment probably has support for variables of some kind. You seem to be asking about `ipython` or Jupyter; could you please [edit] to clarify which tool you are asking about? – tripleee Jul 20 '22 at 08:13

1 Answers1

0

What is that exclamation mark? What language is it? Looks like shell or windows cmd.

For windows cmd:

set reqs=C:/Users/Test/requirements.txt
set whls=C:/Users/Test/whldir
pip download -r %reqs% -d %whls% 

For unix shells:

reqs="/Users/Test/requirements.txt"
whls="/Users/Test/whldir"
pip download -r $reqs -d $whls 
Filip Hanes
  • 645
  • 4
  • 10
  • Perhaps pair this with https://stackoverflow.com/questions/64398183/different-ways-of-setting-environment-variables-in-jupyter-notebook – tripleee Jul 20 '22 at 08:23
  • "*What is that exclamation mark? What language is it?*" Python in a Jupyter Notebook. Exclamation mark is used to run shell commands. – phd Jul 20 '22 at 09:14