由于Lion是全64位系统,我们得让编译器知道所有的编译工作都需要指定为64位,这会让我们之后省点头痛的麻烦。打开 ~/.bash_profile
vim ~/.bash_profile
添加如下代码:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
Xcode
Installing development-related software usually requires the compiler tool-chain that comes with Xcode. There is at least one alternative GCC installer, but I ran into problems with it and recommend sticking with Xcode.
安装开发相关的软件通常需要涉及到XCode自带的编译工具链。这里至少有一种可替代的工具——GCC installer, 但我在使用时遇到了些麻烦因此我推荐坚持使用XCode。
First, download Xcode from the Mac App Store. Make sure you're on a high-bandwidth connection, because this is a massive download. Once it's been downloaded, you should have a 3.2GB app entitled "Install Xcode" in your Applications folder. I recommend backing up this installer in case you ever want to re-install it or install Xcode on any of your other Macs. Once the straightforward Xcode installation process has finished, proceed to the next section.
Homebrew
Sometimes you may need cross-platform software — usually without a GUI and accessible only via the command line — that isn't readily available via the Mac App Store. As someone who used MacPorts for years, I can't begin to explain the relative awesomeness that is Homebrew. It's an indispensable tool that should be in every Mac developer's arsenal, so let's install it:
有些时候你需要跨平台的软件——通常都是不带图形界面只能通过命令行方式访问的——这在苹果app商店中可不是随处可见的哦。作为MacPorts的多年用户,我到现在都无法表达出对Homebrew的赞美之情。这是每一个Mac开发者不可或缺的神器啊,让我们装上它:
ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
That's it — Homebrew is now installed. While it should have the latest version of Homebrew and its formulae, let's run the update command just in case:
就是这样 —— 现在Homebrew已经安装好了。按照惯例,Homebrew应该是最新版本,以防万一,让我们运行一下升级命令
brew update
If the "brew update" command produces an error, make sure /usr/local is owned by you and not by root:
如果“brew update”命令执行出错,请确保文件夹/usr/local的所有者权限是你本人而不是root:
sudo chown $USER /usr/localbrew update
The Homebrew wiki has a full command list and a bunch of other useful information, but here's a quick command to install some packages that I often find useful across all my Macs:
Homebrew的wiki上有全部的命令列表还有一些其他的有用的信息,这里有个快捷的命令用来安装一些我觉得十分有用而且能够在我所有的Mac系统上运行的工具包:
brew install bash-completion byobu growlnotify ssh-copy-id wget Python模块安装包
Let's say you want to install a Python package, such as the fantastic virtualenv environment isolation tool. Nearly every Python-related article for Mac OS X tells the reader to install it thusly:
你打算安装一个Python包,比如经典的virtualenv环境隔离工具。在Mac系统上几乎每一篇与Python相关的文章都告诉读者要这样安装:
sudo easy_install virtualenv
Here's why I don't do it that way:
我不这么做的原因是:
installs with root permissions
1. 安装需要root权限
installs into the global /Library instead of the user's
2. 这会安装到全局的/Library文件夹中,而不是用户文件夹
"Distribute" has less bugs than the default legacy easy_install
3. “Distribute”安装系统比默认的easy_install的bug要少
If I install a Python package and decide I want to delete it, I like having the option to use the Finder to drag it to the Trash without any permission-related complaints. Plus, keeping the Python packages isolated to the user account just makes more sense to me. Last but not least, Distribute is a fork of Setuptools/easy_install that aims to be more reliable with less bugs.
如果我安装了一个Python包之后又决定删除它时,我喜欢用Finder将它拖到回收站,没有任何权限相关的警告跳出来烦我。而且,对我而言保持Python包和用户账户隔离显得更有意义一些。最后,“Distribute”是一系列的安装工具,其目标就是更加稳定,更少的bug。
Traditionally, I've always used the "--user" flag to install Python packages into ~/.local, a behavior that was consistent across Macs, Linux, and other UNIX systems. It seems Lion has changed this behavior, however, installing into ~/Library/Python/2.7 when it encounters the --user flag. Since I prefer to have this location remain consistent across the various systems I encounter, I changed the flag from "--user" to the more specific "--prefix=~/.local". Whichever you choose, please keep in mind that the instructions here assume the latter.
一般来说,我总是使用“--user”选项来把Python包安装到~/.local目录中。这种行为在Mac,Linux和其他Unix系统上是一致的。看起来Lion系统似乎改变了这种行为,当Lion遇到“--user”选项时,Python包将安装到~/Library/Python/2.7目录中。由于我希望将这个路径在不同的系统中保持
统一,因此我将“--user”选项改为更具体的“--prefix=~/.local”。不管你选择哪种,请记住后面的内容假定你选择的是后者。
With that tangent behind us, let's install Distribute:
带着这种考量,我们安装Distribute:
安装到~/.local目录唯一的缺点就是我们需要手动加入一些路径到PATH和PYTHONPATH环境变量中去。编辑一下.bash_profile吧...
增加下面几行代码:
# Path ------------------------------------------------------------if [ -d ~/.local/bin ]; then export PATH=~/.local/bin:$PATH exists.fi# Python path -----------------------------------------------------if [ -d ~/.local/lib/python2.7/site-packages ]; then export PYTHONPATH=~/.local/lib/python2.7/site-packages:$PYTHONPATHfi# Load in .bashrc -------------------------------------------------
source ~/.bashrc
Let's load those directives now via:
现在,让我们加载这些设定:
source ~/.bash_profile
Lion's easy_install is normally located in /usr/bin, so let's make sure that our local version is the one that's used by default:
Lion系统自带的easy_install通常放在/usr/bin目录下,因此这里要确保我们自己安装的版本是系统默认的:
which easy_install
确保得到的结果是~/.local/bin/easy_install, 这样我们就全设置好了! virtualenv and virtualenvwrapper(虚拟环境和虚拟环境包装层)
... and see the results in our web browser. For those that are new to Django, the Django Tutorial is a good place to learn how to continue building your project.
Now that you have a Django project started, use your preferred version control system to make your first commit. For Mercurial, that would be:
现在你已经有了一个Django项目工程,快使用你最趁手的版本管理工具来做第一次提交吧,对于Mercurial,那就是:
hg init projectcd projecthg addhg commit -m "Initial commit" 配置文件(类Unix系统中的配置文件都是以.开头的,因此原文的dotfiles这里就是指的配置文件)
While I've posted excerpts of my dotfiles above, you can get the whole enchilada from my Bitbucket repository.
尽管我已经在前文给出了我的配置文件摘录,你可以在我的存储库Bitbucket repository得到全部的配置文件。 咻!搞定
Congrats! It takes a bit of time to set up a new system, but it's well worth the journey. These are the tools of our trade, and we use them every day, so it makes sense to make them as efficient as possible.
恭喜!我们花了一点时间来设定一个新的系统,但这是很值得的。这就是我们的工具,我们将在每天的工作中使用它们,因此很有必要使它们尽可能的高效。
That said, the good can always be made better. What would you do to improve this Lion bootstrap process? Leave a comment below!
那就是说,好的总可以变得更好。对这个Lion系统的启动设置你还可以做什么改进?留下你的意见吧!