Closed lorenzobalzani closed 2 months ago
Hello @lorenzobalzani 👋, I'm here to help you with any bugs, questions, or contributions you may have. Let's work together to resolve the issue you're experiencing.
The issue you're encountering is due to the use of pip._internal.req.parse_requirements
, which is not reliable and can cause the PosixPath
object error. You can resolve this by modifying the requirements_of_file
function to use the packaging.requirements
module instead.
Here's a modified version of the requirements_of_file
function that avoids using pip._internal.req.parse_requirements
:
from packaging.requirements import Requirement
from pathlib import Path
from typing import Dict
def requirements_of_file(path: Path) -> Dict[str, Requirement]:
"""Get a dictionary of package names to requirements from a requirements file."""
with path.open() as f:
lines = f.readlines()
mapping = {}
for line in lines:
line = line.strip()
if line and not line.startswith("#"):
req = Requirement(line)
mapping[req.name] = req
return mapping
To integrate this into your setup.py
script, you can replace the parse_requirements
calls with this function:
from pathlib import Path
required_packages = list(
map(
lambda req: str(req),
requirements_of_file(Path("trulens_eval/requirements.txt")).values()
)
)
optional_packages = list(
map(
lambda req: str(req),
requirements_of_file(Path("trulens_eval/requirements.optional.txt")).values()
)
)
This approach should resolve the PosixPath
issue and ensure compatibility with your environment [1][2].
To continue talking to Dosu, mention @dosu.
I do think that this LLM response does not resolve the issue @sfc-gh-dhuang.
Hey @lorenzobalzani I tried to reproduce error locally and could not do it. One question: you mentioned python version as 3.12 but the error trace mentions the version as 3.11. Could you please check the environment?
Hey @lorenzobalzani I tried to reproduce error locally and could not do it. One question: you mentioned python version as 3.12 but the error trace mentions the version as 3.11. Could you please check the environment?
That's my bad, I've figured out the solution and forgot to update the post. I solved by using an environment with >= Python 3.12.
Bug Description I get this error:
To Reproduce
Expected behavior The error should not happen.
Relevant Logs/Tracebacks
Environment:
Context I am running a Streamlit environment.
@sfc-gh-chu @sfc-gh-jreini