Problem with PYTHONPATH while running tests

Joshua Root jmr at macports.org
Sat Nov 5 18:14:23 PDT 2011


On 2011-11-6 11:35 , Simon Newton wrote:
> On Sat, Nov 5, 2011 at 5:16 PM, Blair Zajac <blair at orcaware.com> wrote:
>>
>> On Nov 5, 2011, at 12:01 PM, Simon Newton wrote:
>>
>>> 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.
>>
>> Great!
>>
>> I suggest updating the Portfile to explicitly run the unit test using ${prefix}/bin/python2.7 instead of modifying the #! line, it's easier that way as it doesn't require modifying the source.
> 
> What's the best way to do that? AFAIK the port code just calls make check.
> 
> Looking at the configure script, it looks like I can pass PYTHON
> pointing to ${prefix}/bin/python2.7 . I think I can get this to
> working by adding:
> 
> configure.env-append PYTHON=${prefix}/bin/python2.7
> 
> to the variant, and then (hopefully) modifying Makefile.am to use the
> value of $PYTHON to run the unittest. Is that the best method?

There's actually a shorthand for setting PYTHON in the configure
environment, 'configure.python ${prefix}/bin/python2.7'.

<http://guide.macports.org/chunked/reference.phases.html#reference.phases.configure>

- Josh


More information about the macports-dev mailing list