PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread poseidon
In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains 
the line


/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it 
should be possible to write


import tau4

in my programs. But it isn't. Despite the fact that 
/home/poseidon/tau4/swr/py3/src is in sys.path, I get a ModuleNotFoundError.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the 
site-packages dir:


ln -s /home/poseidon/tau4/swr/py3/src /usr/lib/python3.6/site-packages/tau4

https://docs.python.org/3.6/library/site.html suggests that PTH files 
only work relative to the site-packages dir. But digging around in e.g. 
StackOverflow I got the impression that absolute paths should work as 
well. If so, what am I doing wrong?


I'm on Arch Linux, Python 3.6.

Kind regards
Paul


--
https://mail.python.org/mailman/listinfo/python-list


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread poseidon

On 15/02/17 12:16, Wolfgang Maier wrote:

On 15.02.2017 10:33, poseidon wrote:

In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It contains
the line

/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
should be possible to write

import tau4

in my programs.



No, that's not what you should expect!
A path file contains paths to be added at interpreter startup to the
package/module search path stored in sys.path. That is, in your example,
if you put a file tau4.py or a tau4 directory with the __init__.py file
inside into /home/poseidon/tau4/swr/py3/src, *then* you could import tau4.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
site-packages dir:

ln -s /home/poseidon/tau4/swr/py3/src
/usr/lib/python3.6/site-packages/tau4



Well this works because now Python finds (following the symlink) a tau4
package (i.e., a directory with that name and an __init__.py file
inside) in /usr/lib/python3.6/site-packages. The .pth file is not
involved in this at all.



Yes, removed it (symlink still there) and it still works. But then, what 
are pth files for? I'd just place a symlink to the package and am done 
with. The path doesn't seem to be needed in sys.path (where it would go 
if placed in a pth file). If I write


from tau4 import datalogging

that works, too. So no need for the path being in sys.path (i.e. in a 
pth file)?




https://docs.python.org/3.6/library/site.html suggests that PTH files
only work relative to the site-packages dir. But digging around in e.g.
StackOverflow I got the impression that absolute paths should work as
well. If so, what am I doing wrong?

I'm on Arch Linux, Python 3.6.

Kind regards
Paul







--
https://mail.python.org/mailman/listinfo/python-list


Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread poseidon

On 15/02/17 14:34, Wolfgang Maier wrote:

On 15.02.2017 13:42, poseidon wrote:

On 15/02/17 12:16, Wolfgang Maier wrote:

On 15.02.2017 10:33, poseidon wrote:

In /usr/lib/python3.6/site-packages I wrote a file tau4.pth. It
contains
the line

/home/poseidon/tau4/swr/py3/src

In /home/poseidon/tau4/swr/py3/src there's an __init__.py file, so it
should be possible to write

import tau4

in my programs.



No, that's not what you should expect!
A path file contains paths to be added at interpreter startup to the
package/module search path stored in sys.path. That is, in your example,
if you put a file tau4.py or a tau4 directory with the __init__.py file
inside into /home/poseidon/tau4/swr/py3/src, *then* you could import
tau4.


It works, if I set a symlink to /home/poseidon/tau4/swr/py3/src in the
site-packages dir:

ln -s /home/poseidon/tau4/swr/py3/src
/usr/lib/python3.6/site-packages/tau4



Well this works because now Python finds (following the symlink) a tau4
package (i.e., a directory with that name and an __init__.py file
inside) in /usr/lib/python3.6/site-packages. The .pth file is not
involved in this at all.



Yes, removed it (symlink still there) and it still works. But then, what
are pth files for? I'd just place a symlink to the package and am done
with. The path doesn't seem to be needed in sys.path (where it would go
if placed in a pth file). If I write

from tau4 import datalogging

that works, too. So no need for the path being in sys.path (i.e. in a
pth file)?



I guess a major point of .pth files is that you only have one or a small
number of files with a clear purpose polluting the containing directory.
Of course, you could put symlinks to all your packages and modules into
site-packages, but what's the point of putting them somewhere else in
the first place? Also, you cannot create symlinks across devices, but
.pth files will work.


Thank you, Wolfgang.

Did the following: Put a symlink tau4 in /home/poseidon/tau4/swr/py3/src 
pointing to this directory. Removed the symlink in the site-packages. 
Restore the pth file tau4.pth containing the line 
/home/poseidon/tau4/swr/py3/src.


Worx! Thank you for sheding light on this!

Paul




Best,
Wolfgang




--
https://mail.python.org/mailman/listinfo/python-list