Registry / testing / python-path

python-path

JSON →
library0.1.3pypypi✓ verified 87d ago

The `python-path` library (version 0.1.3, last updated in 2018) provides a simple context manager for temporarily modifying `sys.path`. It offers a clean way to add directories to Python's import search path, allowing scripts to import modules located in other folders without permanent global modifications. This is particularly useful for safely loading local scripts or modules from dynamically determined paths. The project's release cadence appears inactive.

pip install python-path
INSTALL
IMPORT
SIG · PYTHON-PATH
P
python-path
testingpythonv0.1.3
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PythonPath
from python_path import PythonPath

This quickstart demonstrates how to use the `PythonPath` context manager to temporarily add a directory to `sys.path` for importing modules, and how `sys.path` is automatically restored upon exiting the `with` block.

import os from python_path import PythonPath # Create a dummy module in a temporary directory temp_dir = "./temp_modules" os.makedirs(temp_dir, exist_ok=True) with open(os.path.join(temp_dir, "my_module.py"), "w") as f: f.write("def greet():\n return \"Hello from my_module!\"") # Attempt to import without modifying sys.path (will fail) try: import my_module except ImportError as e: print(f"Expected error: {e}") # Use PythonPath context manager to add the directory to sys.path with PythonPath(temp_dir): import my_module print(my_module.greet()) # After exiting the 'with' block, my_module is no longer importable (sys.path restored) try: import my_module except ImportError as e: print(f"Expected error after context exit: {e}") # Clean up the dummy module and directory os.remove(os.path.join(temp_dir, "my_module.py")) os.rmdir(temp_dir)
Debug
Known issues
deprecatedThe `python-path` library (cgarciae/python_path) has not been updated since 2018. Consider if `pathlib` (standard library) or more actively maintained alternatives for managing import paths are more suitable for new projects.
fix
For general path manipulation, use Python's built-in `pathlib` module. For more robust `sys.path` management in complex projects, evaluate tools like `importlib` utilities or project-specific solutions for module discovery, or consider if the project structure itself can be simplified to avoid `sys.path` manipulation.
affects: <=0.1.3
gotchaWhile `python-path` temporarily modifies `sys.path`, it doesn't prevent name collisions if modules with the same name exist in different added paths or standard library locations. The first module found in `sys.path` will be imported.
fix
Ensure unique module names across your project or be explicit with import statements. If name collisions are unavoidable, carefully manage the order in which paths are added (implicitly, `PythonPath` adds to the beginning of `sys.path` for the duration of the context).
affects: <=0.1.3
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'my_module'
The Python interpreter cannot find the specified module because its containing directory is not in `sys.path`.
fix
Wrap your import statement within a `with PythonPath('path/to/module_directory'):` block to temporarily add the directory to `sys.path`.
ImportError: cannot import name 'PythonPath' from 'python_path' (unknown location)
This usually indicates that the `python-path` library is not installed or the import statement is incorrect.
fix
Ensure the library is installed with `pip install python-path` and use `from python_path import PythonPath`.
Upgrade
Version history
0.1.3latest on PyPI · released Apr 9, 2018
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
python-path — pip install python-path · libregistry