A developer is working on a project that requires the use of a third-party package hosted on a private repository. The developer wants to ensure that the package can be imported without specifying the full repository URL each time. Which approach should be taken?
Trap 1: Append the repository path to sys.path in the script.
sys.path is for local file system paths, not remote repositories.
Trap 2: Place the package files in the site-packages directory manually.
Manual placement is error-prone and not maintainable.
Trap 3: Use os.system to run a pip install command from within the script.
Running pip from within a script is bad practice and unreliable.
- A
Append the repository path to sys.path in the script.
Why wrong: sys.path is for local file system paths, not remote repositories.
- B
Place the package files in the site-packages directory manually.
Why wrong: Manual placement is error-prone and not maintainable.
- C
Configure the repository URL in pip's configuration file or in requirements.txt.
pip configuration allows specifying extra index URLs for package resolution.
- D
Use os.system to run a pip install command from within the script.
Why wrong: Running pip from within a script is bad practice and unreliable.