为什么要显示Pyomo'列出了与Pyomo的不同目录不同的目录?

发布于 2025-01-25 16:54:22 字数 2147 浏览 2 评论 0原文

这更多是关于Linux,PIP和虚拟环境的性质的一般问题。

对于上下文:我一直在设置Python和Pyomo在WSL Ubuntu 20.04上在Windows 10环境的顶部安装了一些优化问题。我已经使用VENV建立了一个虚拟环境,并且从Visual Studio代码和Bash中运行一切都很好。但是,最初,在通过Python终端在VS代码中运行脚本时,我遇到了一个问题,我的Python环境找不到我的PYOMO模块。使用 shis so shie thread ,我能够弄清楚我在VS中在VS中呼唤错误的解释器自从我进入VENV以来,我成功地更改了它 - 现在我能够从Python终端和Bash执行我的代码。

但是,在进行此练习的同时,我意识到,我的PYOMO安装有不同的途径,具体取决于我用来搜索的命令来搜索这一安装,这使我感到困惑,我认为这可能是一个学习的机会,可以更好地了解Linux。

当我在VENV内进行PIP Show pyomo时,我会按照预期得到以下内容:

“在此处输入图像说明”

与我运行pip show pyomo在Venv:

到目前为止,一切都很好,因为据我了解,创建VENV的目的是,您将能够安装独立于全球环境的软件包,模块和依赖项。但是,当我运行哪个pyomopyomo 时,我的目录与pip show pyomo在我的VENV之外,如下所示:

当我导航到每个目录时,我注意到在/usr/local/bin/bin/中有一个可执行文件,而当我转到/usr/时local/lib/python3.8/dist-ackages有一个pyomo目录。我注意到这也发生在VENV中,所以我的问题是,什么是哪种pyomo执行该功能与pip show pyomo不同? 答案是否像显示安装目录的一个命令一样简单,而另一个显示可执行路径?我应该期望所有Python软件包的这种正常行为吗

?其中哪个其中什么都不显示,实际上我找不到/usr/usr/local/bin/bin/>目录:

当我为python3做同样的事情时,我会感到更加困惑,并且我会得到以下内容,其中有可执行文件位于/usr/usr/local/local/bin/code>和<代码>/usr/local/lib/ ”在此处输入图像描述”

预先感谢!

This is more of a general question about the nature of linux, pip, and virtual environments.

For context: I've been setting up python and pyomo to run some optimization problems on a wsl Ubuntu 20.04 installation on top of my Windows 10 environment. I've set up a virtual environment using venv and everything runs fine from both Visual Studio Code as well as Bash; however, initially while running my script via the python terminal in VS Code, I ran into an issue where my python environment couldn't find my pyomo module. Using this S.O. thread, I was able to figure out that I was calling the wrong interpreter within VS Code since I was in a venv, and I changed it successfully - and I am now able to execute my code from both a Python terminal as well as Bash.

However, while doing that exercise I realized that I was getting different paths for my pyomo installation depending on which command I used to search for the installation, which puzzled me, and I figured this could be a learning opportunity to better understand Linux.

When I run pip show pyomo inside my venv, I get the following, as expected:

enter image description here

Compared to when I run pip show pyomo outside of venv:
enter image description here

So far so good, since from what I understand the purpose of creating a venv is that you will be able to install packages, modules, and dependencies independent of your global environment. However, when I run which pyomo and whereis pyomo, I get different directories than with pip show pyomo outside of my venv, as seen below: enter image description here

When I navigate to each directory, I notice that in /usr/local/bin/ there is a pyomo executable, whereas when I go to /usr/local/lib/python3.8/dist-packages there is a pyomo directory. I notice that this also occurs within the venv, so my question is, what is which pyomo doing that is different from pip show pyomo? Is the answer as simple as one command showing the installation directory and another showing the executable path? Is this normal behavior that I should expect with all python packages, and if so, why is the pyomo executable located outside of the pyomo directory?

For example, when I try the same exercise with pandas, I get the following, where which and whereis don't show anything, and indeed I can't find a pandas executable in the /usr/local/bin/ directory:
enter image description here

I get even more confused when I do the same thing for python3 and I get the following, where there are executables located at both /usr/local/bin/ and /usr/local/lib/ enter image description here

Thanks in advance!

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

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

发布评论

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

评论(1

_畞蕅 2025-02-01 16:54:22

大多数Python软件包都不具有可执行文件。 /usr/local/lib中的一个可能只是一个空壳无论当前的Python环境是什么,它都会拾起。

Most Python packages do not have executables. The one in /usr/local/lib is probably just an empty shell that does something like import pyomo / pyomo.run(), and it will pick up whatever the current Python environment is.

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