問題描述
我開始學習 python 并喜歡它.我主要在 Mac 和 Linux 上工作.當我使用 apt-get 安裝 python 模塊時,我發現在 Linux(主要是 Ubuntu 9.04)上它工作正常.我可以毫無問題地導入它.
I'm starting to learn python and loving it. I work on a Mac mainly as well as Linux. I'm finding that on Linux (Ubuntu 9.04 mostly) when I install a python module using apt-get it works fine. I can import it with no trouble.
在 Mac 上,我習慣于使用 Macports 來安裝所有 Unixy 的東西.但是,我發現我安裝的大多數 python 模塊都沒有被 python 看到.我花了一些時間玩 PATH 設置和使用 python_select .沒有什么真正起作用,在這一點上我還沒有真正理解,我只是在閑逛.
On the Mac, I'm used to using Macports to install all the Unixy stuff. However, I'm finding that most of the python modules I install with it are not being seen by python. I've spent some time playing around with PATH settings and using python_select . Nothing has really worked and at this point I'm not really understanding, instead I'm just poking around.
我的印象是 Macports 在管理 python 模塊方面并不普遍.我想使用更被接受"(如果這是正確的話)的方法重新開始.
I get the impression that Macports isn't universally loved for managing python modules. I'd like to start fresh using a more "accepted" (if that's the right word) approach.
那么,我想知道,Mac python 開發人員使用什么方法來管理他們的模塊?
額外問題:
你用的是蘋果的python,還是其他版本?你是從源代碼編譯所有東西,還是有一個運行良好的包管理器(Fink?).
Do you use Apple's python, or some other version? Do you compile everything from source or is there a package manger that works well (Fink?).
推薦答案
最流行的管理 python 包的方法(如果你沒有使用系統包管理器)是使用 setuptools 和 easy_install.它可能已經安裝在您的系統上.像這樣使用它:
The most popular way to manage python packages (if you're not using your system package manager) is to use setuptools and easy_install. It is probably already installed on your system. Use it like this:
easy_install django
easy_install 使用 Python 包索引,這對于 python 開發人員來說是一個了不起的資源.看看周圍有哪些可用的軟件包.
easy_install uses the Python Package Index which is an amazing resource for python developers. Have a look around to see what packages are available.
更好的選擇是 pip,因為它試圖 修復很多與easy_install相關的問題.Pip 使用與 easy_install 相同的軟件包存儲庫,它只是工作得更好.真正需要使用 easy_install 的唯一時間是這個命令:
A better option is pip, which is gaining traction, as it attempts to fix a lot of the problems associated with easy_install. Pip uses the same package repository as easy_install, it just works better. Really the only time use need to use easy_install is for this command:
easy_install pip
之后,使用:
pip install django
在某些時候,您可能想了解一點 virtualenv.如果你在包需求沖突的項目上進行大量 python 開發,virtualenv 是天賜之物.它將允許您擁有各種包的完全不同版本,并根據您的需要在它們之間輕松切換.
At some point you will probably want to learn a bit about virtualenv. If you do a lot of python development on projects with conflicting package requirements, virtualenv is a godsend. It will allow you to have completely different versions of various packages, and switch between them easily depending your needs.
關于使用哪個 python,堅持使用 Apple 的 python 將不會讓您頭疼,但如果您需要更新的版本(我相信 Leopard 是 2.5.1),我會選擇 macports python 2.6.
Regarding which python to use, sticking with Apple's python will give you the least headaches, but If you need a newer version (Leopard is 2.5.1 I believe), I would go with the macports python 2.6.
這篇關于在 Mac 上安裝 python 模塊最兼容的方式是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!