【问题标题】:Installing distribute in Python 3.3 venv (OS X/Homebrew)在 Python 3.3 venv (OS X/Homebrew) 中安装分发
【发布时间】:2012-12-31 04:25:25
【问题描述】:

我一直在尝试在我的 OS X 机器上启动并运行 Python 3.3 的内置“venv”模块。我已经使用 Homebrew 安装了 Python 3.3。

根据文档,创建和切换虚拟环境按您的预期工作:

$ python3 -m venv myvenv
$ source myvenv/bin/activate

我已经测试过这样的东西:

$ echo "YEAH = 'YEAH!'" > myvenv/lib/python3.3/site-packages/thingy.py
$ python
>>> import thingy
>>> print(thingy.YEAH)
'YEAH!'

但是当我尝试安装分发时,它根本不会放在正确的位置。由于某种原因,它坚持尝试安装到/usr/local/lib/python3.3/site-packages/,但失败并显示以下消息:

No setuptools distribution found
running install
Checking .pth file support in /usr/local/lib/python3.3/site-packages/
/Users/victor/myvenv/bin/python -E -c pass
TEST FAILED: /usr/local/lib/python3.3/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python3.3/site-packages/

and your PYTHONPATH environment variable currently contains:

    ''

无论我尝试使用distribute_setup.py 安装还是直接使用源代码分发,都会发生这种情况。我什至尝试过使用--prefix=/Users/victor/myenv,但它仍然尝试将所有内容放入我的“全局”站点包中。

我无法弄清楚为什么会发生这种情况,但它在我的两台机器上是一致的。请注意,sys.prefix 报告了正确的路径(虚拟环境)。

这是 Homebrew 的问题吗?操作系统?蟒蛇 3.3? venv?我?

【问题讨论】:

  • 在 10.8 上使用 python.org 64-/32 位安装程序中的 python.org 3.3.0 将分发 0.6.33 安装到 venv 中对我来说效果很好。
  • 为了 Homebrew 的方便,我已经完全停止使用 python.org。但他们的安装程序也适用于我。所以,这可能是 Homebrew 安装 Python 的方式的问题。
  • FWIW,它也适用于 MacPorts python33 端口。所以,是的,很可能是自制配方中的一些缺陷。
  • Homebrew 已经安装并分发到/usr/local/lib/python3.3/site-packages/。有问题吗?
  • 您可能需要将 PYTHONPATH 设置为 /usr/local/lib/python3.3/site-packages/

标签: python macos homebrew python-3.3


【解决方案1】:

这是 Homebrew 的一个问题,是的,但它现在可以使用 https://github.com/mxcl/homebrew/commit/0b50110107ea2998e65011ec31ce45931b446dab

$ brew update
$ brew rm python3  #if you have installed it before
$ brew install python3
$ cd /tmp
$ which python3
  /usr/local/bin/python3
$ python3 -m venv myvenv 
$ source myvenv/bin/activate
$ wget http://python-distribute.org/distribute_setup.py  # may need brew install wget
$ python3 distribute_setup.py  
  ...
  Finished processing dependencies for distribute==0.6.45
  After install bootstrap.
  Creating /private/tmp/myvenv/lib/python3.3/site-packages/setuptools-0.6c11-py3.3.egg-info
  Creating /private/tmp/myvenv/lib/python3.3/site-packages/setuptools.pth

您会看到分发安装成功到 /tmp 目录。

【讨论】:

    【解决方案2】:

    这是因为homebrew 安装了 distutils 配置文件:

    $ brew cat python3  | grep "Tell distutils" -A5
        # Tell distutils-based installers where to put scripts
        (prefix/"Frameworks/Python.framework/Versions/#{VER}/lib/python#{VER}/distutils/distutils.cfg").write <<-EOF.undent
          [install]
          install-scripts=#{scripts_folder}
          install-lib=#{site_packages}
        EOF
    
    $ mv ~/.local/Frameworks/Python.framework/Versions/3.3/lib/python3.3/distutils/distutils.cfg ~/tmp/
    $ cat ~/tmp/distutils.cfg 
    [install]
    install-scripts=/Users/gatto/.local/share/python3
    install-lib=/Users/gatto/.local/lib/python3.3/site-packages
    $ . venv/bin/activate
    (venv) $ python distribute-0.6.36/distribute_setup.py
    (venv) $ ls venv/lib/python3.3/site-packages/
    distribute-0.6.36-py3.3.egg  easy-install.pth  setuptools-0.6c11-py3.3.egg-info  setuptools.pth 
    

    请参阅 bugs.python.org 上的“distutils.cfg Can Break venv”问题。

    【讨论】:

    猜你喜欢
    • 2014-09-06
    • 2013-12-21
    • 2015-03-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    相关资源
    最近更新 更多