5

私はOSXマシンでPython3.3の組み込みの「venv」モジュールを起動して実行しようとしています。Homebrewを使用して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たが、それでもすべてを私の「グローバル」サイトパッケージに入れようとします。

なぜこれが発生するのか理解できませんが、2台のマシンで一貫しています。sys.prefix正しいパス(仮想環境)を報告することに注意してください。

これはHomebrewの問題ですか?OS X?Python 3.3?venv?自分?

4

2 に答える 2

3

これは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ディレクトリへの配布インストールが正常に行われたことがわかります。

于 2013-06-05T14:13:57.347 に答える
1

これは、homebrewdistutils構成ファイルをインストールするために発生します。

$ 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がvenvを壊す可能性がある」の問題を参照してください。

于 2013-04-22T09:33:26.650 に答える