Problem with PYTHONPATH while running tests

Simon Newton lists at nomis52.net
Sat Nov 5 12:01:37 PDT 2011


On Sat, Nov 5, 2011 at 11:50 AM, Blair Zajac <blair at orcaware.com> wrote:
>
> On Nov 5, 2011, at 11:39 AM, Simon Newton wrote:
>
>> Hi,
>>
>> I have a port, with a python27 variant that depends on
>> protobuf-python27. I've noticed however that when running the test
>> phase, PYTHONPATH doesn't include the install location of
>> protobuf-python27
>> (/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
>> on my system) so the tests fail.
>>
>> I believe I need to use
>>
>> test.env-append PYTHONPATH=${PATH_TO_DEP_INSTALL_LOCATION}
>>
>> but I don't know how to get the install location of a dependency from
>> within a port file.
>>
>> Any hints?
>
> If protobuf-python27 is successfully installed then it shouldn't need PYTHONPATH set up.
>
> Could the test be picking up Apple's python 2.7 from /usr/bin instead of from $prefix/bin?
>
> Can you from the command line do this:
>
> $ python
> Python 2.7.2 (default, Aug 23 2011, 21:00:36)
> [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> Setting tab completion.
>>>> import google.protobuf
>>>> google.protobuf
> <module 'google.protobuf' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/protobuf/__init__.pyc'>


That appears to be what is happening:

$ which python
/usr/bin/python


$ python
Python 2.6.1 (r261:67515, Aug  2 2010, 20:10:18)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.protobuf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named google.protobuf

$ port list installed | grep protobuf
protobuf-cpp                   @2.4.1          devel/protobuf-cpp
protobuf-python26              @2.4.1          devel/protobuf-python26
protobuf-python27              @2.4.1          devel/protobuf-python27


If I change the #! line to point to /opt/local/bin/python2.7 the tests
work correctly.

Simon


More information about the macports-dev mailing list