找到 MacPorts 包吗?

发布于 2024-11-09 17:11:21 字数 523 浏览 4 评论 0原文

我刚刚通过 MacPorts 安装了 py27-numpy 包,当我使用此命令时,python 将找不到该模块: import scipy

我使用了 help('modules') 命令并且scipy 端口没有出现。

显然,路径配置不正确,或者 MacPorts 没有安装在正确的位置,但无论哪种方式,知道这个包安装在哪里都可以解决我的问题。

在哪里可以找到 MacPorts 安装的软件包 py27-scipy 的路径?

echo $PATH 命令的输出:

/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/ bin:/usr/X11/bin:directory/bin

我在这些位置都找不到该包。

感谢您的帮助。

I just installed the py27-numpy package via MacPorts and python will not find the module when I use this command: import scipy

I used the help('modules') command and the scipy port did not come up.

Clearly the path is not configured correctly or MacPorts is not installing in the correct place, but either way, it would solve my problem to know where this package is being installed.

Where can I find the path to MacPorts-installed package, py27-scipy?

Output of echo $PATH command:

/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:directory/bin

I cannot find the package in any of those locations.

Thanks for the help.

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

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

发布评论

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

评论(6

七分※倦醒 2024-11-16 17:11:21

要查找已安装组件的位置,请使用 contents 子命令:

port contents py27-numpy

至于使用 python 查找包,请参阅 @fardjad 的回复

To find the location of installed components, use the contents subcommand:

port contents py27-numpy

As for getting python to find the package, see @fardjad's response.

滿滿的愛 2024-11-16 17:11:21

您的路径不正确。它似乎正在选择另一个 Python 2.7,可能是使用 python.org 或其他地方的二进制安装程序安装的,而不是 MacPorts 安装的。尝试从 PATH 中删除 /Library/Frameworks/Python.framework/Versions/2.7/bin 或直接调用 MacPorts Python:

/opt/local/bin/python2.7

Your PATH is incorrect. It appears to be picking up another Python 2.7, likely one installed using a binary installer from python.org or elsewhere, and not the MacPorts installed one. Try removing the the /Library/Frameworks/Python.framework/Versions/2.7/bin from PATH or just invoke the MacPorts Python directly:

/opt/local/bin/python2.7
何以笙箫默 2024-11-16 17:11:21

默认情况下,MacPorts 应在 /opt/local/Library/Frameworks/Python.framework/2.7/site-packages 中安装 Python 软件包。因此,请确保在 .profile 文件中设置 $PYTHONPATH 环境变量:

export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/site-packages"

MacPorts should install Python packages in /opt/local/Library/Frameworks/Python.framework/2.7/site-packages by default. So make sure to set $PYTHONPATH environment variable in your .profile file:

export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/site-packages"
你在看孤独的风景 2024-11-16 17:11:21
sudo port select --set python python27

是在系统范围内安装 port 的 python 的最佳答案

sudo port select --set python python27

is the best answer to install port's python system-wide

微凉徒眸意 2024-11-16 17:11:21

由于 Homebrew 只使用最新的 Mac 系统版本,而 MacPorts 则用于中间的其他版本,我很困惑,直到我发现 Python 位置因安装程序而异

这里有一个固执己见的提示:为您的项目使用 virtualenvs,并且不要更改 MacPorts 的默认版本。我不会也不想记得在做某件事的过程中更新我的python,所以我依赖virtualenvs。选择并找到计算机上的 python 版本,然后 mkvirtualenv --python=/found/u/python3.X getawesome

With Homebrew only using the latest, the Mac system version, and MacPorts for the others in-between, I was confused until I found python locations differ depending on the installer.

Here's an opinionated tip: Use virtualenvs for your projects and don't change your default version with the MacPorts. I won't and don't want to remember to updoot my python in the middle of something so I rely on virtualenvs. Choose and find the python version on the computer, then mkvirtualenv --python=/found/u/python3.X getawesome.

一曲爱恨情仇 2024-11-16 17:11:21

基于 Jeremy W. Sherman 的回答

我检查了我的 python 版本

python --version
Python 3.8.5

和位置:

which python
/opt/local/bin/python

然后尝试:

sudo port contents python38 

其中列出了 7285行:

Port python38 contains:
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/Info.plist
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/MacOS/IDLE
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/MacOS/Python
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/PkgInfo
  ...
  /opt/local/share/man/man1/python3.8.1

将其与 fardjad 的答案 结合会导致:

sudo port contents python38 | grep site-packages

输出:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/README.txt

因为我们需要将命令修改为:

dirname $(sudo port contents python38 | grep site-packages)

给出所需的目录:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages

因此可能会得到单行:

Macports 中的单行 PYTHONPATH 设置:

 export PYTHONPATH=$(dirname $(sudo port contents python38 | grep site-packages))

,我们可以检查结果:

echo $PYTHONPATH
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages

作为参考,请参阅 Eclipse Liclipse python IDE 用于设置 PATH 外观的对话框 - 您可能希望为完全指定的 PYTHONPATH 包含更多目录。

Liclipse 对话框用于Python PATH选择

Based on Jeremy W. Sherman's answer

I checked my python version

python --version
Python 3.8.5

and location:

which python
/opt/local/bin/python

and then tried:

sudo port contents python38 

which lists 7285 lines:

Port python38 contains:
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/Info.plist
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/MacOS/IDLE
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/MacOS/Python
  /Applications/MacPorts/Python 3.8/IDLE.app/Contents/PkgInfo
  ...
  /opt/local/share/man/man1/python3.8.1

combining that with fardjad's answer leads to:

sudo port contents python38 | grep site-packages

with the output:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/README.txt

since we need the directory modifying the command to:

dirname $(sudo port contents python38 | grep site-packages)

gives the desired directory:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages

so it's possible to end up with the one-liner:

One-Line PYTHONPATH setting in macports:

 export PYTHONPATH=$(dirname $(sudo port contents python38 | grep site-packages))

and we can check the result:

echo $PYTHONPATH
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages

For reference see how the Eclipse Liclipse python IDE dialog for setting the PATH looks - there are some more directories you might want to include for a fully specified PYTHONPATH.

Liclipse dialog for Python PATH selection

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