为什么要显示Pyomo'列出了与Pyomo的不同目录不同的目录?
这更多是关于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时,我会按照预期得到以下内容:
到目前为止,一切都很好,因为据我了解,创建VENV的目的是,您将能够安装独立于全球环境的软件包,模块和依赖项。但是,当我运行哪个pyomo
和pyomo
时,我的目录与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:
Compared to when I run pip show pyomo
outside of venv:
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:
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:
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/
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数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 likeimport pyomo
/pyomo.run()
, and it will pick up whatever the current Python environment is.