2013-02-26 138 views
22

我正在關注一個名爲Starting a Django 1.4 Project the Right Way的教程,其中介紹瞭如何使用virtualenv和virtualenvwrapper等。終端:shell啓動文件在哪裏?

有讀取的一段:

如果您在使用PIP安裝包(我不明白爲什麼你不會),就可以同時獲得的virtualenv和virtualenvwrapper通過簡單的安裝後者。

$ pip install virtualenvwrapper 

它的安裝後,以下行添加到你的shell啓動文件(.zshrc,的.bashrc,.profile文件等)。

export WORKON_HOME=$HOME/.virtualenvs 
    export PROJECT_HOME=$HOME/directory-you-do-development-in 
    source /usr/local/bin/virtualenvwrapper.sh 

重新加載啓動文件時(例如源.zshrc),你準備好去。

我正在運行Mac OSX,並不知道我周圍的終端太好。作者是什麼意思shell's start-up file (.zshrc, .bashrc, .profile, etc)?我在哪裏可以找到這個文件,以便我可以添加這三行?

另外,他是什麼意思由reload your start up file (e.g. source .zshrc)

我將不勝感激OSX特有的詳細回覆。

回答

28

你可能會使用bash所以只是這3個行添加到~/.bash_profile

$ cat >> ~/.bash_profile 
export WORKON_HOME=$HOME/.virtualenvs 
export PROJECT_HOME=$HOME/directory-you-do-development-in 
source /usr/local/bin/virtualenvwrapper.sh 
^D 

其中^D意味着你鍵入控制 + d(EOF)。

然後要麼關閉終端窗口,打開一個新的,或者您也可以「刷新」你.bash_profile這樣的:

$ source ~/.bash_profile 
+1

有一點輕蔑:「.profile」可以被許多不同的shell讀取,其中一些可能不會將'source'識別爲'.'的更易讀的同義詞。使用'。/usr/local/bin/virtualenwrapper.sh'代替第三行。或者,將這三行代替放入'.bash_profile'中。 – chepner 2013-02-27 01:18:43

+0

如果.bash_profile已經存在,則根本不會讀取.profile。 – user495470 2013-02-27 05:21:50

+0

感謝您的評論 - 我已經更新了明確使用'.bash_profile'而不是'.profile'的答案。 – 2013-02-27 06:32:44

4

如果你使用bash,這通常意味着〜/ .bash_profile中。

在Terminal和iTerm中,新shell默認是登錄shell,因此根本不讀取〜/ .bashrc。如果爲某個其他平臺編寫的指令告訴您將某些內容添加到.bashrc,則通常必須將其添加到.bash_profile中。

如果〜/ .profile和〜/ .bash_profile都存在,則只讀取.bash_profile。 .profile也被其他shell讀取,但許多你添加到.bash_profile的東西都不適用於它們。

從/usr/share/doc/bash/bash.html:

當bash被調用以交互登錄殼,或作爲非交互式殼與--login選項時,它首先如果該文件存在,則讀取並執行文件/ etc/profile中的命令。讀取該文件後,它會按照該順序查找〜/ .bash_profile,〜/ .bash_login和〜/ .profile,並從第一個存在且可讀的命令讀取和執行命令。

[...]

當啓動不是登錄shell的交互式shell時,如果該文件存在,bash將讀取並執行〜/ .bashrc中的命令。

0

我使用了一種我認爲易於維護的方法。 如果你有時使用Ubuntu系統,它也可以工作,但是我會在我的答案中確定解決OP的OSX需求。

  1. 在你的主目錄,例如創建一個.aliases文件與您的別名(ES) ~/.aliases

  2. 使用source ~/.aliases從您的.bashrc文件(每次執行新的shell進程時)執行此文件。這就是你需要爲Ubuntu btw做的所有事情。

  3. 在OSX通話.bashrc~/.profile文件,即有~/.bash_profile包含:source ~/.bashrc

1

我有蟒蛇安裝,所以我加這3行到〜/ .bash_profile

export WORKON_HOME=$HOME/.virtualenvs 
export PROJECT_HOME=$HOME/Documents/Python 
source /Users/Username/anaconda3/bin/virtualenvwrapper.sh 

然後通過以下方式重新載入配置文件:

$ source ~/.bash_profile