我一直试图在我的os x机器上安装并运行python 3.3的内置“venv”模块。我已经用自制软件安装了Python3.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!'

但当我尝试安装Distribute时,它根本不会在正确的位置运行。出于某种原因,它坚持尝试安装到/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报告正确的路径(虚拟环境)。
这是自制啤酒的问题吗?操作系统X?蟒蛇3.3?维夫?我?

最佳答案

这是自制啤酒的问题,是的,但从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

您将看到成功地将distribute安装到/tmp目录中。

07-26 08:51
查看更多