Home > other >  How to get python package requirements from another folder?
How to get python package requirements from another folder?

Time:04-23

This is so simple and don't understand why it isn't working.

I have my CMD opened in folder1. Its working directory is folder1.

folder1 --> folder2

I have a bunch of python files in folder2. I would like to obtain its requirements.txt file and have it reside within folder1.

Again, with my CMD opened in folder1, I run pip freeze --path ./folder2 > requirements.txt

It returns an empty requirements.txt file within folder1. If I run pip freeze within folder2 I obtain a list of requirements no problem.

This seems so basic, but why is --path not working the way I want it?

CodePudding user response:

You are mixing project folders with where pip installs it's site-packages. This is what the --path parameter refers to. Since you don't seem to be familiar with virtual environments, you don't have any and your 2 project folders are using exactly the same packages and you get the requirements.txt simply by

pip freeze > requirements.txt

This is not different for your 2 project folders.

CodePudding user response:

What pip freeze outputs is the list of packages that he things are installed. Usually it just reads site-packages. The path parameter just restricts which packages it should listed, so you are saying take all site-packages from folder 1 and restrict them to this under folder2, which obviously returns empty list.

What you want to do is run proper pip - I guess you have some virtualenv under folder2, so it would be folder2/<your venv>/bin/pip freeze. If you havent, than actually all things you installed via pip lands into the same, global site-packages, so you won't be able to filter only this used by files in folder2.

  • Related