English 中文(简体)
Pip instalation for Python 3.11 in docker
原标题:

I have Dockerfile to build image for Django project that uses Python 3.11 and runs in poetry environment (see content below). Problem is when I try to donwload get-pip.py file and run it using Python, it says no such file or directory but it should be in the same directory where Dockerfile is. I don t know, but why isn t it there?

P.S. I use docker desktop with WSL 2 (Ubuntu 20.04) and Dockerfile is in project directory (where poetry.lock and pyproject.toml files are), /website is directory where django project is.

# Download image of Ubuntu 20.04
FROM ubuntu:20.04

# To prevent interactive dialogs
ENV TZ=Europe 
    DEBIAN_FRONTEND=noninteractive

# Update and install necessary packages
RUN apt-get update 
# Install necessary packages to allow compilation of source code
    && apt-get install -y --no-install-recommends 
    tzdata 
    build-essential 
    checkinstall 
    libreadline-gplv2-dev 
    libncursesw5-dev 
    libssl-dev 
    libsqlite3-dev 
    tk-dev 
    libgdbm-dev 
    libc6-dev 
    libbz2-dev 
    software-properties-common 
# Install python 3.11
    && apt-get update 
    && add-apt-repository ppa:deadsnakes/ppa 
    && apt-get install -y --no-install-recommends 
    python3.11

# Install pip for Python 3.11
RUN curl -sS -O https://bootstrap.pypa.io/get-pip.py | python3.11
# THERE S AN ERROR
RUN python3.11 get-pip.py

# Install poetry
ENV POETRY_VERSION 1.4.2
RUN python3.11 -m pip3.11 install "poetry==$POETRY_VERSION"

# Install dependencies
RUN poetry install

# Run poetry env
ENTRYPOINT ["poetry", "shell"]

# Go to website folder
WORKDIR /website

# Run Django server
CMD ["python3.11", "manage.py", "runserver"]
问题回答

You are using pipe (|) to forward it to python, so the file doesnt end up in the directory but as stdin for python.311

You have two options

  • download it via curl without piping it further

  • pipe it into python as you do now, but then you dont have to execute it explicitly (RUN python3.11 get-pip.py) because that s what you did on previous line via piping

You can just pass the curl output directly to python input to run get-pip.py. This answer will help you.





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签