2011-07-08 97 views
6

我通過mac上的mac端口安裝了python 2.7。我通過macports安裝了virtualenv(py27-virtualenv @ 1.6.1_0(active))。當發出命令:virtualenv demo_venv --no-site-packages時,我得到這個錯誤:-bash:virtualenv:command not found。它不是選擇virtualenv了@一切,所以我需要它符號鏈接到我的python27位置?使用MacPorts安裝後未找到virtualenv命令

+1

當你在bash提示符下運行'virtualenv'時,你會得到什麼? –

+0

什麼都沒有。它只是回到一個空的bash提示符。 – demet8

+0

好吧,這意味着它不在你的道路上。 –

回答

1

你需要確保virtualenv在PATH,儘管它應該是,如果它被正確安裝。

+0

我現在檢查。它應該在我的道路上,不知道爲什麼它不會。謝謝。 – demet8

3

MacPorts的安裝版本鏈接當使用MacPorts時,您需要確保/opt/local/bin位於您的shell PATH環境變量上,在這裏,我同時顯示安裝了py26-virtualenvpy27-virtualenv/opt/local/bin(默認位置爲MacPorts)

$ echo $PATH 
/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Developer/Tools 
$ ls -l /opt/local/bin/virtuale* 
lrwxr-x--- 1 root admin 13 Oct 15 2009 /opt/local/bin/[email protected] -> virtualenv2.6 
lrwxr-xr-x 1 root wheel 74 May 17 02:20 /opt/local/bin/[email protected] -> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenv 
lrwxr-xr-x 1 root wheel 74 May 17 02:29 /opt/local/bin/[email protected] -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv 
lrwxr-xr-x 1 root wheel 88 Jun 27 2010 /opt/local/bin/[email protected] -> /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/virtualenvw 

一般來說,如果你想知道有哪些文件,MacPort口安裝在哪裏,使用port contents找出:

$ port contents py27-virtualenv 
Port py27-virtualenv contains: 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/PKG-INFO 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/SOURCES.txt 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/dependency_links.txt 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/entry_points.txt 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/not-zip-safe 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-1.6.1-py2.7.egg-info/top_level.txt 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.pyc 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/__init__.py 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/__init__.pyc 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/distribute-0.6.16.tar.gz 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/pip-1.0.1.tar.gz 
    /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv_support/setuptools-0.6c11-py2.7.egg 
    /opt/local/bin/virtualenv-2.7 
    /opt/local/share/doc/py27-virtualenv/index.txt 
    /opt/local/share/doc/py27-virtualenv/news.txt 
+0

內德再次感謝,你的幫助總是感激。 – demet8

+0

當我這樣做:端口內容py27-virtualenv我得到你所擁有的。 Python2.7運行良好&py27-virtualenv表示它已經通過macports安裝和(活動)。當我走時:哪個virtualenv在返回時仍然會獲得一個空的bash shell。我嘗試了一個符號鏈接:sudo ln -s/opt/local/var/macports/software/py27-virutalenv/opt/local/bin它仍然不起作用。我最初嘗試沒有sudo的符號鏈接,但是我拒絕了權限。我假設的Macports不喜歡那樣。我有這個設置在另一臺Mac上運行良好,但這是一個痛苦的屁股。我不知道是什麼問題。謝謝。 – demet8

+0

我也得到這個: - demetriusford $ ls -l/opt/local/bin/virtuale * lrwxr-xr-x 1 root admin 74 Jul 6 16:27 /opt/local/bin/virtualenv-2.7 - >/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv – demet8

4

的命令是virtualenv-2.7,不只是virtualenv

如果查看包內容,可以看到沒有安裝名爲virtualenv的可執行文件。

2

如果使用virtualenvwrapper,則可以將shell環境配置爲指向正確的virtualenv腳本。安裝py27-virtualenvwrapper端口,這些行添加到您的Bash配置文件:當您使用virtualenvwrapper命令

export VIRTUALENVWRAPPER_VIRTUALENV=/opt/local/bin/virtualenv-2.7 
source /opt/local/bin/virtualenvwrapper.sh-2.7 

沒有其他路徑兩輪牛車或符號鏈接應要求:

% mkvirtualenv demo_venv --no-site-packages 
35

正如你提到的,使用MacPorts提供了pyXX-virtualenv軟件包的幾個版本。你需要告訴它的版本你想默認使用的MacPorts:

port select --list virtualenv 
port select --set virtualenv virtualenv27 
which virtualenv 

在這之後,你應該能夠只需鍵入virtualenv(假設MacPorts的bin目錄在你的路徑)。

+5

這個答案應該是標記爲正確的答案。這是在MacPorts中處理此問題的正確方法。 –

+0

這的確是正確的方法。另外,對於zsh用戶,確保在執行'port select'後發出'rehash'。 –