Setting Pythonpath programmatic

dieter dieter at handshake.de
Mon Dec 16 02:45:17 EST 2019


Prasad Rajassekaran <prasadautomationtesting at gmail.com> writes:
> I would want to set python path programmatic in my project. So that, all other directories files can be imported without any issues.

You can extend "sys.path" programmatically to control
where Python looks for top level packages/modules (as
you apparently have already tried - it should have worked).

You may also read about ".pth" files (= "path configuration files"),
documented with Python's "site" module. It allows a folder on "sys.path"
to specify where else to look for top level packages/modules.

I have seen cases where "sys.path" extensions had not the
expected effects. This has been with so called "namespace packages"
(this is some kind of distributed package, where package components
can be found in unrelated locations). I never was able to
find the cause: apparently, it was related to the
discrepancy between the modern installation approach (the namespace
package components become centralized on installation) and
the traditional approach (the components remain distributed);
for me, it looked like a Python bug affecting the case when both
approaches have been applied to the same namespace package.
I do not think that your problem is related to this case.



More information about the Python-list mailing list