Django, Docker, and Pipenv - Error adding new packages












0















Using Pipenv with Docker is causing some issues in my Django project.



I've installed Django locally with Pipenv which generates a Pipfile and Pipfile.lock. Then used startproject to start a new Django project.



Then I add a Dockerfile file.



# Dockerfile
FROM python:3.7-slim

ENV PYTHONUNBUFFERED 1

WORKDIR /code
COPY . /code

RUN pip install pipenv
RUN pipenv install --system


And a docker-compose.yml file.



# docker-compose.yml
version: '3'

services:
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000


And run docker-compose up --build to build the image and start the container. Everything works.



Now here's the issue...I want to add a new package, let's say psycopg2 so I can use PostgreSQL.



So...update my docker-compose.yml to add PostgreSQL.



# docker-compose.yml
version: '3'

services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db

volumes: postgres_data:


And update the DATABASE config in settings.py.



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}


Now if I install psycopg2-binary locally like pipenv install psycopg2-binary this "should" sync with Docker. But I get "No module named 'psycopg2'` errors".



Ok so maybe I need to install it directly within Docker:



$ docker-compose exec web pipenv install psycopg2-binary` 


Nope, same error.



Maybe I need to generate the lock file within Docker?



$ docker-compose exec web pipenv lock


Again no. So the issue is the state of Pipenv...I feel like I'm close but just not quite grasping something here.



Anyone see the error?










share|improve this question























  • did you run docker-compose exec web pipenv install psycopg2-binary to install the package and docker-compose up to start?

    – Siyu
    Nov 20 '18 at 20:11











  • Yes and then docker-compose up, no build needed. Still same error which is very strange to me.

    – wsvincent
    Nov 20 '18 at 20:14











  • Did you try to install psycopg2-binary in your Dockerfile and then rebuild with docker-compose build web?

    – Julio Daniel Reyes
    Nov 20 '18 at 20:37











  • Yes, but that didn't work for me either sadly. I think the issue is around not rebuilding the image when there is a local code change, like a new software package. Still trying to find the elegant solution...

    – wsvincent
    Nov 20 '18 at 20:47











  • try using pipenv install --system --deploy --ignore-pipfile stackoverflow.com/questions/46503947/…

    – MjZac
    Nov 21 '18 at 7:41
















0















Using Pipenv with Docker is causing some issues in my Django project.



I've installed Django locally with Pipenv which generates a Pipfile and Pipfile.lock. Then used startproject to start a new Django project.



Then I add a Dockerfile file.



# Dockerfile
FROM python:3.7-slim

ENV PYTHONUNBUFFERED 1

WORKDIR /code
COPY . /code

RUN pip install pipenv
RUN pipenv install --system


And a docker-compose.yml file.



# docker-compose.yml
version: '3'

services:
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000


And run docker-compose up --build to build the image and start the container. Everything works.



Now here's the issue...I want to add a new package, let's say psycopg2 so I can use PostgreSQL.



So...update my docker-compose.yml to add PostgreSQL.



# docker-compose.yml
version: '3'

services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db

volumes: postgres_data:


And update the DATABASE config in settings.py.



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}


Now if I install psycopg2-binary locally like pipenv install psycopg2-binary this "should" sync with Docker. But I get "No module named 'psycopg2'` errors".



Ok so maybe I need to install it directly within Docker:



$ docker-compose exec web pipenv install psycopg2-binary` 


Nope, same error.



Maybe I need to generate the lock file within Docker?



$ docker-compose exec web pipenv lock


Again no. So the issue is the state of Pipenv...I feel like I'm close but just not quite grasping something here.



Anyone see the error?










share|improve this question























  • did you run docker-compose exec web pipenv install psycopg2-binary to install the package and docker-compose up to start?

    – Siyu
    Nov 20 '18 at 20:11











  • Yes and then docker-compose up, no build needed. Still same error which is very strange to me.

    – wsvincent
    Nov 20 '18 at 20:14











  • Did you try to install psycopg2-binary in your Dockerfile and then rebuild with docker-compose build web?

    – Julio Daniel Reyes
    Nov 20 '18 at 20:37











  • Yes, but that didn't work for me either sadly. I think the issue is around not rebuilding the image when there is a local code change, like a new software package. Still trying to find the elegant solution...

    – wsvincent
    Nov 20 '18 at 20:47











  • try using pipenv install --system --deploy --ignore-pipfile stackoverflow.com/questions/46503947/…

    – MjZac
    Nov 21 '18 at 7:41














0












0








0


0






Using Pipenv with Docker is causing some issues in my Django project.



I've installed Django locally with Pipenv which generates a Pipfile and Pipfile.lock. Then used startproject to start a new Django project.



Then I add a Dockerfile file.



# Dockerfile
FROM python:3.7-slim

ENV PYTHONUNBUFFERED 1

WORKDIR /code
COPY . /code

RUN pip install pipenv
RUN pipenv install --system


And a docker-compose.yml file.



# docker-compose.yml
version: '3'

services:
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000


And run docker-compose up --build to build the image and start the container. Everything works.



Now here's the issue...I want to add a new package, let's say psycopg2 so I can use PostgreSQL.



So...update my docker-compose.yml to add PostgreSQL.



# docker-compose.yml
version: '3'

services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db

volumes: postgres_data:


And update the DATABASE config in settings.py.



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}


Now if I install psycopg2-binary locally like pipenv install psycopg2-binary this "should" sync with Docker. But I get "No module named 'psycopg2'` errors".



Ok so maybe I need to install it directly within Docker:



$ docker-compose exec web pipenv install psycopg2-binary` 


Nope, same error.



Maybe I need to generate the lock file within Docker?



$ docker-compose exec web pipenv lock


Again no. So the issue is the state of Pipenv...I feel like I'm close but just not quite grasping something here.



Anyone see the error?










share|improve this question














Using Pipenv with Docker is causing some issues in my Django project.



I've installed Django locally with Pipenv which generates a Pipfile and Pipfile.lock. Then used startproject to start a new Django project.



Then I add a Dockerfile file.



# Dockerfile
FROM python:3.7-slim

ENV PYTHONUNBUFFERED 1

WORKDIR /code
COPY . /code

RUN pip install pipenv
RUN pipenv install --system


And a docker-compose.yml file.



# docker-compose.yml
version: '3'

services:
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000


And run docker-compose up --build to build the image and start the container. Everything works.



Now here's the issue...I want to add a new package, let's say psycopg2 so I can use PostgreSQL.



So...update my docker-compose.yml to add PostgreSQL.



# docker-compose.yml
version: '3'

services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
web:
build: .
command: python /code/manage.py migrate --noinput && /code/manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- 8000:8000
depends_on:
- db

volumes: postgres_data:


And update the DATABASE config in settings.py.



DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432
}
}


Now if I install psycopg2-binary locally like pipenv install psycopg2-binary this "should" sync with Docker. But I get "No module named 'psycopg2'` errors".



Ok so maybe I need to install it directly within Docker:



$ docker-compose exec web pipenv install psycopg2-binary` 


Nope, same error.



Maybe I need to generate the lock file within Docker?



$ docker-compose exec web pipenv lock


Again no. So the issue is the state of Pipenv...I feel like I'm close but just not quite grasping something here.



Anyone see the error?







django docker docker-compose pipenv






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 19:40









wsvincentwsvincent

95111




95111













  • did you run docker-compose exec web pipenv install psycopg2-binary to install the package and docker-compose up to start?

    – Siyu
    Nov 20 '18 at 20:11











  • Yes and then docker-compose up, no build needed. Still same error which is very strange to me.

    – wsvincent
    Nov 20 '18 at 20:14











  • Did you try to install psycopg2-binary in your Dockerfile and then rebuild with docker-compose build web?

    – Julio Daniel Reyes
    Nov 20 '18 at 20:37











  • Yes, but that didn't work for me either sadly. I think the issue is around not rebuilding the image when there is a local code change, like a new software package. Still trying to find the elegant solution...

    – wsvincent
    Nov 20 '18 at 20:47











  • try using pipenv install --system --deploy --ignore-pipfile stackoverflow.com/questions/46503947/…

    – MjZac
    Nov 21 '18 at 7:41



















  • did you run docker-compose exec web pipenv install psycopg2-binary to install the package and docker-compose up to start?

    – Siyu
    Nov 20 '18 at 20:11











  • Yes and then docker-compose up, no build needed. Still same error which is very strange to me.

    – wsvincent
    Nov 20 '18 at 20:14











  • Did you try to install psycopg2-binary in your Dockerfile and then rebuild with docker-compose build web?

    – Julio Daniel Reyes
    Nov 20 '18 at 20:37











  • Yes, but that didn't work for me either sadly. I think the issue is around not rebuilding the image when there is a local code change, like a new software package. Still trying to find the elegant solution...

    – wsvincent
    Nov 20 '18 at 20:47











  • try using pipenv install --system --deploy --ignore-pipfile stackoverflow.com/questions/46503947/…

    – MjZac
    Nov 21 '18 at 7:41

















did you run docker-compose exec web pipenv install psycopg2-binary to install the package and docker-compose up to start?

– Siyu
Nov 20 '18 at 20:11





did you run docker-compose exec web pipenv install psycopg2-binary to install the package and docker-compose up to start?

– Siyu
Nov 20 '18 at 20:11













Yes and then docker-compose up, no build needed. Still same error which is very strange to me.

– wsvincent
Nov 20 '18 at 20:14





Yes and then docker-compose up, no build needed. Still same error which is very strange to me.

– wsvincent
Nov 20 '18 at 20:14













Did you try to install psycopg2-binary in your Dockerfile and then rebuild with docker-compose build web?

– Julio Daniel Reyes
Nov 20 '18 at 20:37





Did you try to install psycopg2-binary in your Dockerfile and then rebuild with docker-compose build web?

– Julio Daniel Reyes
Nov 20 '18 at 20:37













Yes, but that didn't work for me either sadly. I think the issue is around not rebuilding the image when there is a local code change, like a new software package. Still trying to find the elegant solution...

– wsvincent
Nov 20 '18 at 20:47





Yes, but that didn't work for me either sadly. I think the issue is around not rebuilding the image when there is a local code change, like a new software package. Still trying to find the elegant solution...

– wsvincent
Nov 20 '18 at 20:47













try using pipenv install --system --deploy --ignore-pipfile stackoverflow.com/questions/46503947/…

– MjZac
Nov 21 '18 at 7:41





try using pipenv install --system --deploy --ignore-pipfile stackoverflow.com/questions/46503947/…

– MjZac
Nov 21 '18 at 7:41












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400385%2fdjango-docker-and-pipenv-error-adding-new-packages%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53400385%2fdjango-docker-and-pipenv-error-adding-new-packages%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement