Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing distribute in Python 3.3 venv (OS X/Homebrew)

I've been trying to get up and running with the built-in "venv" module of Python 3.3 on my OS X machine. I've installed Python 3.3 using Homebrew.

As per the docs, creating and switching virtual environment works as you'd expect:

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

And I've tested something like this:

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

But when I try to install distribute, it simply won't go in the proper place. For some reason, it insists on trying to install into /usr/local/lib/python3.3/site-packages/, which fails with the following messages:

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:

    ''

This happens regardless if I try to install using distribute_setup.py or using the source distribution directly. I've even tried using --prefix=/Users/victor/myenv but it still tries to put everything in my "global" site-packages.

I can't figure out why this happens, but it's consistent on two of my machines. Note that sys.prefix reports the correct path (the virtual environment).

Is this a problem with Homebrew? OS X? Python 3.3? venv? Me?

like image 829
vicvicvic Avatar asked Oct 05 '22 12:10

vicvicvic


1 Answers

This has been an issue with Homebrew, yes, but it is working now since 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

You see that distribute install successfully into the /tmp dir.

like image 136
Samuel John Avatar answered Oct 10 '22 03:10

Samuel John