找到 MacPorts 包吗?
我刚刚通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要查找已安装组件的位置,请使用
contents
子命令:至于使用
python
查找包,请参阅 @fardjad 的回复。To find the location of installed components, use the
contents
subcommand:As for getting
python
to find the package, see @fardjad's response.您的路径不正确。它似乎正在选择另一个 Python 2.7,可能是使用 python.org 或其他地方的二进制安装程序安装的,而不是 MacPorts 安装的。尝试从 PATH 中删除
/Library/Frameworks/Python.framework/Versions/2.7/bin
或直接调用 MacPorts Python: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:默认情况下,MacPorts 应在
/opt/local/Library/Frameworks/Python.framework/2.7/site-packages
中安装 Python 软件包。因此,请确保在.profile
文件中设置$PYTHONPATH
环境变量: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:是在系统范围内安装 port 的 python 的最佳答案
is the best answer to install port's python system-wide
由于 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
.基于 Jeremy W. Sherman 的回答
我检查了我的 python 版本
和位置:
然后尝试:
其中列出了 7285行:
将其与 fardjad 的答案 结合会导致:
输出:
因为我们需要将命令修改为:
给出所需的目录:
因此可能会得到单行:
Macports 中的单行 PYTHONPATH 设置:
,我们可以检查结果:
作为参考,请参阅 Eclipse Liclipse python IDE 用于设置 PATH 外观的对话框 - 您可能希望为完全指定的 PYTHONPATH 包含更多目录。
Based on Jeremy W. Sherman's answer
I checked my python version
and location:
and then tried:
which lists 7285 lines:
combining that with fardjad's answer leads to:
with the output:
since we need the directory modifying the command to:
gives the desired directory:
so it's possible to end up with the one-liner:
One-Line PYTHONPATH setting in macports:
and we can check the result:
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.