如何使pip安装python模块在我当前的python2.7安装在mac上(而不是2.6)



我有一台mac,我使用macports安装了python。我喜欢这种方式,因为我可以手动安装numpy, scipy等,而不需要像enthought这样的预构建包。我现在想安装web.py,但是在尝试通过easy_install和pip安装它之后,我无法在交互式python命令行上导入它。安装时,它还显示:Installed/Library/Python/2.6/site-packages/web.py-0.37-py2.6。python 2.7.3 (default, Oct 22 2012, 06:12:28) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

当我输入'which python'时,我得到:/opt/local/bin/python

所以我的问题是:如何使easy_install和/或pip安装模块在python安装,我进入时,我只是在命令行上键入'python' ?

如果你在python中使用macports,那么你也应该通过macports安装pip和easy_install。你的路径上似乎有一个非重要文件。

安装py27-pip将在您的路径上提供一个pip-2.7可执行脚本,类似于easy_install。

macports版本在其名称中包含python版本,以便允许安装多个版本的python。如果您只需要pip,那么创建一个bash别名或将pip-2.7脚本链接到您路径中的某个目录中的pip。

我也在我的Mac上做Django开发,但发现了一个更好的解决方案(允许轻松使用pip),使用Vagrant + VirtualBox + Chef在本地VM中安装Django(这将允许您复制生产服务器设置)。然后,您可以在本地浏览器上访问它。这里有一个很好的介绍:

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

我已经更新了教程提供的vagrantfile,以使用precise32(与可能在32位系统上的人保持兼容),一个较新的Ubuntu版本,并包括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

最新更新