admin管理员组文章数量:1401407
RUN pip install git+https://${GITHUB_TOKEN}@github//packages.git#egg=mypackage&subdirectory=mypackage is not working in my Dockerfile
This is my Dockerfile
FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r requirements.txt
# Accept GITHUB_TOKEN as a build argument
ARG GITHUB_TOKEN
RUN echo $GITHUB_TOKEN
# Fail if GITHUB_TOKEN is not set
RUN test -n "$GITHUB_TOKEN" || (echo "ERROR: GITHUB_TOKEN is not set" && exit 1)
RUN pip install git+https://${GITHUB_TOKEN}@github/<username>/packages.git#egg=mypackage&subdirectory=mypackage
When the image is built, all packages in requirements.txt are successfully installed, however the github mypackage cannot be found when i try to import it in my code.
Note. the GITHUB_TOKEN is being successfully passed to Docker build in the cloud build step:
'--build-arg', 'GITHUB_TOKEN=${_GITHUB_TOKEN}'
And the pip installation works if I add the github package line to requirements.txt (with hard coded token)
Im wondering if the package is being pip installed somewhere unexpected. Any thoughts?
RUN pip install git+https://${GITHUB_TOKEN}@github//packages.git#egg=mypackage&subdirectory=mypackage is not working in my Dockerfile
This is my Dockerfile
FROM python:3.9-slim
COPY . /app
WORKDIR /app
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir -r requirements.txt
# Accept GITHUB_TOKEN as a build argument
ARG GITHUB_TOKEN
RUN echo $GITHUB_TOKEN
# Fail if GITHUB_TOKEN is not set
RUN test -n "$GITHUB_TOKEN" || (echo "ERROR: GITHUB_TOKEN is not set" && exit 1)
RUN pip install git+https://${GITHUB_TOKEN}@github/<username>/packages.git#egg=mypackage&subdirectory=mypackage
When the image is built, all packages in requirements.txt are successfully installed, however the github mypackage cannot be found when i try to import it in my code.
Note. the GITHUB_TOKEN is being successfully passed to Docker build in the cloud build step:
'--build-arg', 'GITHUB_TOKEN=${_GITHUB_TOKEN}'
And the pip installation works if I add the github package line to requirements.txt (with hard coded token)
Im wondering if the package is being pip installed somewhere unexpected. Any thoughts?
Share Improve this question edited Mar 24 at 15:58 President James K. Polk 42.1k29 gold badges109 silver badges145 bronze badges asked Mar 22 at 16:02 pablowilks2pablowilks2 3397 silver badges21 bronze badges1 Answer
Reset to default 0Your question is not a minimal repro and thus difficult for us to help.
I am unable to repro your issue with an attempt at repro'ing it:
FROM ghcr.io/astral-sh/uv:debian-slim
RUN apt-get update && \
apt-get install -y git && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Instead of `uv add`, use `uv venv` and install both packages using `uv pip install`
# Flask for a conventional install
# Requests for a pip install git+https example
RUN uv init && \
uv venv && \
uv pip install flask && \
uv pip install git+https://github/psf/requests.git
COPY main.py main.py
ENTRYPOINT ["uv","run","main.py"]
And:
main.py
:
def main():
for library_name in ["flask","requests"]:
try:
__import__(library_name)
print(f"Found: {library_name}")
except ImportError:
print(f"Not found: {library_name}")
if __name__ == "__main__":
main()
And:
Q="79527704"
podman build \
--tag=stackoverflow:${Q} \
--file=${PWD}/Dockerfile \
${PWD}
podman run \
--interactive --tty --rm \
--name=${Q} \
stackoverflow:${Q}
Yields:
Found: flask
Found: requests
Both packages are available as expected.
Perhaps try enumerating site-packages
in the container file:
RUN ls -la /path/to/site-packages
本文标签: pythonWhy is RUN pip install from Github not working in my DockerfileStack Overflow
版权声明:本文标题:python - Why is RUN pip install from Github not working in my Dockerfile? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744309248a2599949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论