如何从另一个文件夹中获取Python软件包要求?

发布于 2025-01-23 18:00:38 字数 555 浏览 2 评论 0原文

这是如此简单,不明白为什么它不起作用。

我的CMD在folder1中打开。它的工作目录是folder1

folder1 --> folder2

我在folder2中有一堆python文件。我想获得其unignts.txt文件,并将其存放在folder1中。

同样,在我的CMD中打开folder1,我运行pip冻结-path ./folder2> unignts.txt

它在folder1中返回一个空unigess.txt文件。如果我在folder2中运行pip Freeze,我会获得无问题的要求列表。

这似乎是如此的基础,但是为什么- 路径无法按照我想要的方式工作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掐死时间 2025-01-30 18:00:38

您将项目文件夹与PIP安装的网站包装混合。这就是 - 路径参数所指的。由于您似乎不熟悉虚拟环境,因此您没有任何内容,并且您的2个项目文件夹正在使用完全相同的软件包,并且您获得了要求

pip freeze > requirements.txt

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.

妞丶爷亲个 2025-01-30 18:00:38

什么pip Freeze输出是安装东西的软件包列表。通常,它只是读取站点包路径参数仅限于应该列出的包装,因此您要说将所有站点包装从文件夹1中获取,并将其限制在folder2 下,显然会返回空列表。

您想做的是运行适当的pip-我想您在folder2下有一些 virtualenv ,因此它将是folder2/< venv>/bin/bin/bin/bin/bin/bin/ PIP冻结。如果您没有,那么实际上是通过pip降落到同一 site-packages 的所有事物,因此您将无法仅过滤文件。在folder2中。

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.

乞讨 2025-01-30 18:00:38

我对此的解决方案是使用pipReqs

cmdfolder1中打开

a unignts.txt文件出现在folder1中。这些软件包基于folder2中的python文件。

My solution to this was to use pipreqs

With CMD opened in folder1, I ran pipreqs ./folder2 --savepath requirements.txt

A requirements.txt file appeared in folder1. The packages were based on the python files in folder2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文