简体   繁体   English

在OS X 10.8.1上设置Python和Virtualenv?

[英]Setting up Python and Virtualenv on OS X 10.8.1?

I recently reinstalled my OS X and my python setup is gone with it. 我最近重新安装了OS X,并且python设置也随之消失了。 I can't remember how I set it up before and now I am having a lot of trouble. 我不记得以前如何设置它,现在遇到了很多麻烦。 I followed this guide (http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/#python) up to the part that makes a sym link. 我遵循了本指南(http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/#python)直至构成符号链接的部分。 (CTRL+F this in the webpage: "ln -s /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/Current") (在网页中按CTRL + F组合键:“ ln -s /usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/Current”)

It didn't produce "/usr/local/bin/python" when I put in "which python". 当我放入“哪个python”时,它没有产生“ / usr / local / bin / python”。 Instead, it gave me "/usr/bin/python". 相反,它给了我“ / usr / bin / python”。

What am I doing wrong? 我究竟做错了什么? This is so frustrating! 真令人沮丧! How can I fix this, or is there a better step by step tutorial that allows me to install python via Homebrew and then install virtualenv on top of that python installation? 如何解决此问题,或者是否有更好的分步教程,允许我通过Homebrew安装python,然后在该python安装之上安装virtualenv?

FINALLY SOLVED IT! 终于解决了!

the PATH variable has a short circuit logic to it. PATH变量具有短路逻辑。 It goes down each variable(folder locations like "/etc/paths", "~/.profile", etc). 它沿着每个变量下降(文件夹位置如“ /etc/paths”、“~/.profile”等)。 When it finds your command ("python") in the folder it is looking at, that's what the terminal gives you. 当它在要查看的文件夹中找到您的命令(“ python”)时,这就是终端所提供的。

To solve my problem, you have to put "/usr/local/bin"(where the homebrew python installation is) ahead of "/usr/bin"(where the default OS X python installation is.). 为了解决我的问题,您必须将“ / usr / local / bin”(本地安装python的位置)放在“ / usr / bin”(默认的OS X python安装的位置)之前。 To do this, open "/etc/paths" in terminal with: 为此,请在终端中使用以下命令打开“ / etc / paths”:

open /etc/paths

this will open up the "paths" file in your default text editor. 这将在默认文本编辑器中打开“路径”文件。 Now it should look something like this: 现在看起来应该像这样:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

Since the file is in a protected folder, its not going to let you edit it directly. 由于该文件位于受保护的文件夹中,因此您无法直接对其进行编辑。 When you edit the file, it will ask to make a duplicate. 当您编辑文件时,它将要求进行复制。

Save the duplicate to desktop, and move "/usr/local/bin" to the top, like this: 将副本保存到桌面,然后将“ / usr / local / bin”移动到顶部,如下所示:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Remove the actual file("/etc/paths") and copy your duplicate file from the desktop. 删除实际文件(“ / etc / paths”),然后从桌面复制重复的文件。 Be sure to remove the .txt extension on the duplicate. 确保删除重复项上的.txt扩展名。 If you are not sure how to do this, go to Finder > Preferences > Advanced and check Show all filename extensions. 如果不确定如何执行此操作,请转至Finder>首选项>高级,然后选中显示所有文件扩展名。 Rename the file to "paths" 将文件重命名为“路径”

Log out and log back in to refresh it and you are done! 注销并重新登录以刷新它,您完成了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM