0

Say I have a virtualenv environment myenv1 and another, myenv2. I have some packages installed in myenv1, and I would like to install them on myenv2 as well. Is there a way to install them in myenv2 using myenv1?

I referred to the following link, but apparently that requires a requirement.txt to be present.

However, I have installed many packages on the go, and I do not have a prepared requirement.txt for myenv1. Also, the second step requires downloading the required packages again to a folder. Is there a way to achieve the said without downloading anything again?

ghost
  • 1,107
  • 3
  • 12
  • 31
  • did you try to follow the steps from the linked question's answer? `pip install` won't delete any packages you have already installed in myenv2 – FObersteiner Aug 06 '20 at 10:30
  • I just want a couple of packages, and so I'm refraining from the said approach. – ghost Aug 06 '20 at 10:42
  • well, you could also edit the requirements.txt before calling for the download / install? – FObersteiner Aug 06 '20 at 10:43
  • The second step in the link still requires downloading the packages again. I wonder if there was a workaround for that. – ghost Aug 06 '20 at 10:50

1 Answers1

0

pipdeptree is great for determining what packages you installed and to bring over to a new environment.

The docs demonstrate how you can generate a requirements file that only contains the packages you installed (and not their dependencies):

pipdeptree --freeze --warn silence | grep -E '^[a-zA-Z0-9\-]+' > requirements.txt

You could then pare down that requirements file to only the packages you really need and then follow the pip download steps. That would minimize your download.


If you don't want to download any packages again, you could try using pip's cache directory:

pip install -r requirements.txt --find-links=%LocalAppData%\pip\cache\wheels

However, I don't know how long pip's caching strategy would keep old installed packages around. Read more on pip's Caching docs. Maybe you could pip download --find-links to to pull out the cached packages and then pip download to get the rest?

idbrii
  • 10,975
  • 5
  • 66
  • 107