2013-04-24 52 views
0

我有一個mac,我使用macports安裝python。我喜歡這種方式,因爲我可以手動安裝numpy,scipy等,而不必像預先構建的軟件那樣亂用。我現在想安裝web.py,但在通過easy_install和pip嘗試安裝之後,我無法將它導入交互式python命令行。 安裝時,它還會顯示:Installed /Library/Python/2.6/site-packages/web.py-0.37-py2.6.egg,而當我輸入'python'時,它會顯示以下內容:Python 2.7.3(default ,2012年10月22日,06:12:28)[GCC 4.2.1(Apple Inc. build 5666)(dot 3)]達爾文如何在mac上(而不是2.6)在我當前的python2.7安裝中安裝python模塊?

當我輸入'which python'時:/ opt/local/bin/python

所以我的問題是:如何在python安裝中使用easy_install和/或pip安裝模塊,當我在命令行中輸入「python」時,輸入該模塊?

回答

2

如果您正在使用的MacPorts蟒,那麼你應該安裝PIP,並通過MacPorts的easy_install的爲好。你似乎有一個非macports pipon你的路徑。

安裝py27-pip將爲您提供一個pip-2.7可執行腳本,類似於easy_install。

macports版本的名稱中有python版本,以允許安裝多個版本的python。如果你只需要點子,然後創建一個bash別名或鏈接pip-2.7腳本來點擊你的路徑上的一個目錄。

+0

感謝您的提示。現在我只是得到一個錯誤,因爲我已經安裝了一個pip版本:Error:org.macports.activate for port py27-pip returned:Image error:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/ bin/pip已經存在,並且不屬於註冊的端口。無法激活端口py27-pip。使用'port -f activate py27-pip'強制激活。在Linux上,我通常會執行sudo apt-get purge pip(或類似操作),但是如何在OSX上卸載現有的pip? – kramer65 2013-05-15 02:58:22

+0

不幸的是,你沒有通過macports安裝它,因此'不屬於註冊的端口'只是強制激活它將覆蓋它 – Mark 2013-05-15 09:59:36

+0

不幸的是,這仍然不起作用。我做了'sudo port -f install py27-pip',然後'sudo pip install web.py'再次導致「Requirement already satisfied」,而在Python交互式命令行中導入web仍然給我一個「ImportError:No模塊名爲web「。任何其他想法? – kramer65 2013-05-15 15:05:21

0

我也在我的Mac上做Django開發,但已經找到了一個更好的解決方案(它允許使用pip)來使用Vagrant + VirtualBox + Chef在本地VM中安裝Django(這將允許您複製生產服務器設置)。然後您可以在本地瀏覽器上訪問它。有一個很好的介紹在這裏:

http://blog.smalleycreative.com/tutorials/setup-a-django-vm-with-vagrant-virtualbox-and-chef/

我已經更新到本教程提供使用precise32(留在人誰可能是在32位系統兼容),一個新的Ubuntu發行版的vagrantfile,幷包括emacs,python和MySQL客戶端。我希望這有幫助。必要

其他的git回購協議:

git clone git://github.com/opscode-cookbooks/emacs 
git clone git://github.com/opscode-cookbooks/python 
git clone git://github.com/opscode-cookbooks/mysql 

而且Vagrantfile:

Vagrant::Config.run do |config| 
    config.vm.define :djangovm do |django_config| 
    # Every Vagrant virtual environment requires a box to build off of. 
    django_config.vm.box = "precise32" 

    # The url from where the 'config.vm.box' box will be fetched if it 
    # doesn't already exist on the user's system. 
    django_config.vm.box_url = "http://files.vagrantup.com/precise32.box" 

    # Forward a port from the guest to the host, which allows for outside 
    # computers to access the VM, whereas host only networking does not. 
    django_config.vm.forward_port 80, 8080 
    django_config.vm.forward_port 8000, 8001 

    # Enable provisioning with chef solo, specifying a cookbooks path (relative 
    # to this Vagrantfile), and adding some recipes and/or roles. 
    # 
    django_config.vm.provision :chef_solo do |chef| 
     chef.cookbooks_path = "cookbooks" 
     chef.add_recipe "apt" 
     chef.add_recipe "apache2::mod_wsgi" 
     chef.add_recipe "build-essential" 
     chef.add_recipe "git" 
     chef.add_recipe "vim" 
     chef.add_recipe "emacs" 
     chef.add_recipe "python" 
     chef.add_recipe "mysql" 
    # 
    # # You may also specify custom JSON attributes: 
    # chef.json = { :mysql_password => "foo" } 
    end 
    end 
end 
+0

嗨FlipperPA。感謝您的提示。我看了一下流浪者,安裝了它,然後試圖開火。我遇到了一些錯誤並放棄了(我很快就知道)。主要的是我想使用本地解決方案。但是,無論如何感謝提示! – kramer65 2013-05-16 17:40:21