安装在Python 3.3 venv中分发(OS X / Homebrew)

我一直试图在我的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的问题吗? OS X? Python 3.3? VENV?我?

最佳答案
这是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目录中.

相关文章

最近做自动化测试时,深感自己对前端涉猎太少,加上对这块比...
homebrew本身就是一个git仓库。使用homebrew安装软件包时,会...
一、Homebrew安装、卸载等命令Homebrew的安装和卸载都非常简...
在mac系统中,使用homebrew可以很方便的管理包。按照官网的说...
我按照说明从这里使用brew安装mysqlhttps://gist.github.com...
我在macOS10.12.4上安装了nginx1.10.3和php5.5.38作为开发服...