Python 无法识别 MacPorts 安装的软件包

发布于 2025-01-06 06:06:50 字数 1946 浏览 1 评论 0原文

预先感谢您的建议!

背景:

相对于这个网站上的人,我对编程很陌生,尽管进行了一些研究,但我不熟悉使用 Unix 类型的 shell,不熟悉管理包真正涉及的内容,也不熟悉在“博士”之外完成的任何事情。 .Java”IDE 或默认 R GUI。我有一台 2008 年末的 macbook,操作系统为 OSX 10.5.8

我的目标:

我正在尝试在 Python 中安装以下软件包:scipy、numpy、matplotlib、networkX

我的故事:

据我所知,我的 10.5.8 安装了一个Python 2.5,系统需要它来运行,你真的不应该乱搞。我安装的软件包需要 Python 2.7,因此在重新格式化我的计算机后,我使用 Python 网站上的 .dmg 安装了适用于 OSX 10.3 的 Python 2.7.2(2.7.X 提供的最新 Python/OSX)。然后,我使用 Apple 站点上的 .dmg(适合我的操作系统的版本)安装了 XCode,并使用其站点上的 .dmg 安装了 MacPorts(适合我的操作系统的版本)。然后,我相信我使用 MacPorts 来安装这些软件包:

sudo port install py27.numpy

但是,当我尝试导入我显然已安装的软件包时,Python 告诉我它们不存在。我很确定我的机器上只有 2 个版本的 Python,OSX 的 2.5 和我的 2.7.2(我如何检查这个?),如果我检查正在运行的 Python 版本,无论是通过 Shell 还是通过 IDLE,我得到:

>>> import sys
>>> print sys.version
2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 14:13:39) 
[GCC 4.0.1 (Apple Inc. build 5493)]

如果我运行“which python”,我得到:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

当我检查 MacPorts 安装软件包的位置时,

port contents py27-packagename

我得到的目录主要位于:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

中有几个目录

/opt/local/share/py27-matplotlib/examples/
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/share/doc/networkx-1.5/

,每个目录中有一个目录

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/f2py
/opt/local/share/doc/py27-matplotlib/CHANGELOG
/opt/local/share/doc/py27-matplotlib/README.txt
/opt/local/share/doc/py27-matplotlib/TODO

我的问题:

如何获取 Python识别我的包裹?理想情况下,我想对其进行设置,以便可以使用 Python IDLE,以及从命令行调用它。

我尝试在以下位置复制一些解决方案: 找到 MacPorts 包吗? 但我不太明白我在做什么,所以很难适应那里正在做的事情。

再次感谢大家!

Thank you in advance for the advice!

Background:

Relative to the people on this site I'm new to programming, and despite some research I'm not familiar with using Unix-type shells, with what managing packages really involves, or with anything which is done outside of the "Dr. Java" IDE or default R GUI. I have a late-2008 macbook with OSX 10.5.8

My Goal:

I'm trying to get the following packages installed in Python: scipy, numpy, matplotlib, networkX

My Story:

From what I understand my 10.5.8 comes installed with a Python 2.5, which the system needs for its functioning, and you really shouldn't mess with. The packages I installed require Python 2.7, so after reformatting my machine, I installed Python 2.7.2 for OSX 10.3 (the latest Python/OSX that was offered of 2.7.X) using the .dmg off of the Python website. Then, I installed XCode using the .dmg (appropriate version for my OS) off of the Apple site, and installed MacPorts (appropriate version for my OS) using the .dmg off of their site. Then, I believe I used MacPorts to install the packages:

sudo port install py27.numpy

However, when I try to import the packages I've apparently installed, Python tells me they don't exist. I'm pretty sure I have only 2 versions of Python on my machine, 2.5 for OSX and 2.7.2 for me (how do I check this?), and if I check which version of Python is running, whether through the Shell or through the IDLE, I get:

>>> import sys
>>> print sys.version
2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 14:13:39) 
[GCC 4.0.1 (Apple Inc. build 5493)]

If I run "which python" i get:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

When I check where MacPorts installed the packages using

port contents py27-packagename

I get directories mostly in:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

with a few directories in

/opt/local/share/py27-matplotlib/examples/
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/share/doc/networkx-1.5/

and one directory each in

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/f2py
/opt/local/share/doc/py27-matplotlib/CHANGELOG
/opt/local/share/doc/py27-matplotlib/README.txt
/opt/local/share/doc/py27-matplotlib/TODO

My Question:

How do I get Python to recognize my packages?? Ideally I'd like to set it up so I can use the Python IDLE, as well as invoking it from the command line.

I've tried replicating some of the solutions at:
Locate MacPorts package?
But I don't really understand what I'm doing all that well so It's difficult to adapt what's being done there.

Thank you again everyone!

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

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

发布评论

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

评论(1

自在安然 2025-01-13 06:06:50

我最初将你的问题误解为标准问题 - 为什么我不能运行我的 macports python?但事实上,您指定您正在尝试使用自安装的python,而且确实如此。问题是,python 不知道在哪里寻找 macports 安装的库。

您所链接的问题是在正确的轨道上。请参阅此响应,但将路径替换为您的 macports 库的实际路径,即:

export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH"

看看这是否行不通窍门!

i initially misunderstood your question to be the standard one of - why can't i run my macports python? but in fact, you specified that you are trying to use the self-installed python, and you are. the problem is, that python doesn't know where to look for your libraries which macports installed.

you were on the right track with that question you linked to. see this response, but replace the path with your actual path to your macports libs, viz:

export PYTHONPATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH"

see if that doesn't do the trick!

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