开发者

Trouble importing modules in Python IDEs

开发者 https://www.devze.com 2022-12-20 06:05 出处:网络
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 h

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 开发者_Go百科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


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 of easy_install should ensure that everything is found. In rare cases, you might have to fool with sys.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消