Python无法识别MacPorts已安装的软件包 [英] Python will not recognize MacPorts installed packages

查看:123
本文介绍了Python无法识别MacPorts已安装的软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前谢谢您的建议!

背景:

相对于该网站上的人,我是编程的新手,尽管进行了一些研究,但我对使用Unix类型的shell,管理包真正涉及的内容或在""Java博士" IDE或默认的R GUI.我有一台装有OSX 10.5.8的2008年底的Macbook

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

我的目标:

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

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

我的故事:

据我了解,我的10.5.8随Python 2.5一起安装,系统需要它来运行它,而您真的不应该将它弄乱.我安装的软件包需要Python 2.7,因此在重新格式化计算机后,我使用Python网站上的.dmg为OSX 10.3(版本2.7.X提供了最新的Python/OSX)安装了Python 2.7.2.然后,我在Apple网站之外使用.dmg(适合我的操作系统的版本)安装XCode,并在网站附近使用.dmg安装MacPorts(适合我的操作系统的版本).然后,我相信我使用MacPorts安装了软件包:

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

但是,当我尝试导入显然已经安装的软件包时,Python告诉我它们不存在.我敢肯定,我的机器上只有2个Python版本,OSX是2.5版本,而我是2.7.2版本(如何检查?),以及是否通过Shell或Shell检查运行的是哪个版本的Python?通过IDLE,我得到:

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)]

如果我运行哪个python",我会得到:

If I run "which python" i get:

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

当我检查MacPorts在何处安装软件包时

When I check where MacPorts installed the packages using

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并从命令行调用它.

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.

我尝试在以下位置复制一些解决方案: 查找MacPorts软件包? 但是我不太了解自己在做什么方面的出色表现,因此很难适应那里所做的事情.

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.

再次感谢大家!

推荐答案

我最初误解了您的问题,使之成为标准问题之一-为什么我不能运行macports python?但实际上,您指定了您正在尝试使用自安装的python,并且确实如此.问题是,python不知道在哪里可以找到安装了macports的库.

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.

与您链接到的问题有关,您处在正确的轨道上.参见此响应,但将路径替换为macports库的实际路径,即:

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"

看看那有什么用!

这篇关于Python无法识别MacPorts已安装的软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆