在 Python IDE 中导入模块时出现问题
是的,我对此有点厌倦了,所以希望你能帮我一劳永逸地解决这个问题。
我真的很困惑我的 MacBook 上的 Python 发生了什么。我正在运行 OS X 10.6.2 并已从网站安装了 python(包含 IDLE 的软件包)。这工作得很好,事实上 IDLE 会运行我想要的一切,只是我不想使用 IDLE。
因此,我尝试了 Netbeans,这令人恼火 - 它似乎在完全错误的位置寻找库(即使我尝试强制它在我的计算机上的不同位置查找 Python)。 Eclipse 做了非常类似的事情。
这会导致更多问题;究竟应该如何将模块安装到Python中? -使用 MacPorts 它似乎消失在 opt/local/var/macports 的某个深处,除了 IDLE 之外什么也找不到它。 - 从命令行运行“python setup.py install”通常会出现各种错误,例如:
warning: in /opt/local/lib/libfreetype.dylib, file is not of required architecture
然后有时会在 Libraries\Python\2.6\site-packages 中转储一些不起作用的内容。 - 安装任何模块的 .dmg 版本实际上似乎完全没有任何作用,也找不到它所做的任何痕迹,即使是在空闲状态下也是如此。
我的机器上似乎运行着不同版本的 Python,不同的 IDE 会在不同的位置寻找 Python 及其模块。除此之外,似乎每种 Python 模块安装方法都将它们放在不同的位置。真的有这么难吗?
是否有强制 Netbeans 运行特定版本的 python 的方法?或者有没有办法强制所有内容仅使用其中一个版本?另外,哪些路径属于哪些版本的Python?
你的,严重困惑!
邓肯
Right I'm getting a bit tired of this so hopefully you can help me sort it out once and for all.
I'm really confused about what's going on with Python on my MacBook. I'm running OS X 10.6.2 and have installed python from the website (the package that includes IDLE). This works absolutely fine, and in fact IDLE will run everything I want to, it's just that I don't want to use IDLE.
So, I tried Netbeans, and it's infuriating - it seems to be looking for libraries in completely the wrong place (even when I try and force it to look in different places for Python on my machine). Eclipse did something very similar.
This leads to more problems; how exactly should one install modules into python?
-Using MacPorts it seemingly disappears into some depths of opt/local/var/macports where it's found by nothing except IDLE.
-Running "python setup.py install" from the command line USUALLY ends up with various errors regarding something like:
warning: in /opt/local/lib/libfreetype.dylib, file is not of required architecture
and then sometimes dumps something in Libraries\Python\2.6\site-packages that doesn't work.
-Installing a .dmg version of any module literally seems to do absolutely nothing, can't find any trace of what it's done with it either, even from IDLE.
It seems to be there's different versions of Python running on my machine, with different IDEs looking to different places for Python and it's modules. Aswell as this it seems that every method of installation of modules for python puts them in different places. Should it really be this difficult?
Is there anyway of forcing Netbeans to run a particular version of python? Or is there a way to force everything to use only one of the versions? Also, which paths belong to which versions of Python?
Yours, Seriously confused!
Duncan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过坚持使用 macports Python 安装来处理这个问题。出于兼容性原因,我对不同 python 版本的混合模块非常谨慎。
使用
python_select
、port
安装的模块和 macports 版本的easy_install
应确保找到所有内容。在极少数情况下,您可能不得不欺骗sys.path
,但这应该只适用于没有更好安装程序的 3rd 方内容。这个解决方案并不完美,但对我来说效果很好。如果您以这种方式启动程序,请确保重新配置编辑器以指向正确的解释器。如果您需要分发软件(并且无法进入
ports
目录),您始终可以创建一个针对本机 Python 安装的安装工具。I deal with this by sticking to the macports Python installation. For compatibility reasons, I'm very wary of mixing modules for different python versions.
Using
python_select
,port
installed modules and the macports version ofeasy_install
should ensure that everything is found. In rare cases, you might have to fool withsys.path
, but that should only be for 3rd party stuff that doesn't have a better installer.This solution isn't perfect, but it's worked ok for me. Just make sure you reconfigure your editor to point to the correct interpreter if you start your programs that way. If you need to distribute your software (and can't get in the
ports
catalog), you can always create a setup tool that targets the native python install.