This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Embedded Python - local directories in pythonXX._pth
Type: behavior Stage:
Components: Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: emve, steve.dower
Priority: normal Keywords:

Created on 2021-07-19 13:42 by emve, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg397797 - (view) Author: emve (emve) Date: 2021-07-19 13:42
When I add mylib to python39._pth, Python treats
it relatively to c:\Python3 (where my embedded python resides).

>>> import sys
>>> print('\n'.join(sys.path))
c:\python3\python39.zip
c:\python3
c:\python3\lib
c:\python3\mylib
c:\python3\lib\site-packages
>>>

However, my mylib directory is in my current project directory,
which is obviously not under c:\Python3

I know that the solution is to enter full path to mylib into python39._pth, but it is quite unconvenient as I have multiple projects, each with its own local modules in mylib directory.

Is there a way to simply add only one mylib
entry into python39._pth?
msg410994 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2022-01-20 00:23
I'm afraid not. The ._pth file is intended for embedding applications that have a static set of search paths.

You may want to try adding a startup file (search for PYTHONSTARTUP) that modifies sys.path directly. Or alternatively if you rename the ._pth file to a regular .pth file, it should disable the isolation protection and use the more flexible algorithm, which *I believe* will resolve relative paths against the current directory rather than where the file lives.
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88839
2022-01-20 00:23:34steve.dowersetnosy: + steve.dower
messages: + msg410994
2021-07-19 13:42:09emvecreate