0

Apologies for the lack of better title..

I wanted to know if the following is possible?

So currently I am using vs-code for python work. In vs-code I install some packages related to vs-code extensions, for example I use black for formatting. The package black is installed in my base python installation. But when I switch to a new virtual environment, I have to reinstall the package. I don't mind reinstalling the package, but when I do pip freeze > requirements.txt, it includes these packages also as dependencies, which I don't want.

My first question is, how can I limit the output of pip freeze > requirements.txt to just include the packages which are actually used in project (by actually I mean, which I am importing). I am open to using other methods for creating requirements.txt.

My second question (sort of on a side) is, when I reinstall the package in new virtual environment, is it creating a new copy of files (given that the same package is installed in base environment). I am using conda for virtual environment and my guess is it is using some sort of caching mechanism to avoid multiple installation.

Thanks for your help and time...

monte
  • 1,482
  • 1
  • 10
  • 26
  • For your first question, perhaps something along the lines of https://stackoverflow.com/questions/58737741/how-to-list-all-python-packages-used-by-a-script-in-python3 ? – Roman Luštrik Mar 31 '23 at 08:03
  • The simple and obvious solution is to manually build your `requirements.txt` to only list the actual dependencies. Every time you `import` something new, also add it to `requirements.txt`. Don't use `pip freeze` for this. – tripleee Apr 10 '23 at 07:26
  • Possible duplicate of https://stackoverflow.com/questions/23640182/ignore-certain-packages-and-their-dependencies-with-pip-freeze – tripleee Apr 10 '23 at 15:10

0 Answers0