2013-04-24 60 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