[SciPy-User] should one put "." into PYTHONPATH

Ondrej Certik ondrej at certik.cz
Mon May 9 19:24:04 EDT 2011


On Mon, May 9, 2011 at 2:49 AM, Ondrej Certik <ondrej at certik.cz> wrote:
> Hi Robert, Jason and Gael,
>
> On Thu, May 5, 2011 at 7:22 PM, Robert Kern <robert.kern at gmail.com> wrote:
>> On Thu, May 5, 2011 at 18:23, Ondrej Certik <ondrej at certik.cz> wrote:
>>> Hi,
>>>
>>> is it a good practice to have the following in .bashrc:
>>>
>>> export PYTHONPATH=$PYTHONPATH:.
>>
>> I don't recommend it. You will get unexpected behavior and waste time
>> chasing down problems that don't actually exist.
>
> The answer is 100% clear: don't fiddle with PYTHONPATH.
>
> Thanks for that, I was undecided. Now I can see, that I need to use
> other solutions to the problem.
>
>>
>>> I know that Ubuntu long time ago had the "." in PYTHONPATH by default,
>>> and then dropped it. The reason why I want it is so that I can develop
>>> in the current directory, by doing things like:
>>>
>>> python examples/a.py
>>>
>>> where 'a.py' imports something from the current directory. I googled a
>>> bit, and found that some people recommend to use "setup.py develop"
>>> instead. I don't use setup.py in my project (I use cmake to mix
>>> Fortran and Python together). So one option for me is to always
>>> install it, and then import it like any other package from
>>> examples/a.py.
>>
>> You don't need to do "python setup.py develop" every time. Nothing
>> actually depends on there being a setup.py. Just add a .pth file into
>> your site-packages listing the directory you want added. E.g. if you
>> have your sympy checkout in /home/ondrej/git/sympy/ you would have a
>> file named sympy.pth (or any other name ending in .pth) in your
>> site-packages directory with just the following contents (without the
>> triple quotes:
>>
>> """
>> /home/ondrej/git/sympy
>> """
>>
>> Then you can run /home/ondrej/git/sympy/examples/a.py however you
>> like, from whichever directory you like.
>
> Wow, thanks for this tip! This works like a charm. That's exactly what
> I was looking for.

So for the record, I have implemented the following simple patch to
Qsnake (http://qsnake.com/):

https://github.com/qsnake/qsnake/commit/2f95f88af7c532a1b81605c6e9bb5dfdb8b219c3

i.e.:

def command_develop():
    print "Adding the current directory into qsnake.pth file:"
    cmd("echo $CUR >> $SPKG_LOCAL/lib/python/site-packages/qsnake.pth",
            echo=True)

and I use it like:

certik1 at pike:~/repos/dftatom(master)$ qsnake develop
Adding the current directory into qsnake.pth file:
echo $CUR >> $SPKG_LOCAL/lib/python/site-packages/qsnake.pth

and then I just do:

Qsnake: certik1 at pike:~/repos/dftatom(master)$ python examples/optimize.py
a =  1000000000.0 N0 =  3000
a =  100000000.0 N0 =  2600
a =  10000000.0 N0 =  2300
....

and everything works as expected. So the paths will get stacked in the
qsnake.pth file. I guess that's ok. The user can then inspect the file
manually and prune it if needed.

Ondrej



More information about the SciPy-User mailing list