Reputation: 936
in the docs it sayes "Note that you cannot install any Python packages into Docker-based project interpreters."
so what is the alternative for that?
The +
button to add packages it dimped and I can't click it to add packages, despite it work very well when I use vertualenv instead of docker compose, or docker.
Upvotes: 4
Views: 2526
Reputation: 13023
If you're using -- for whatever reason -- a container to run your python interpreter, PyCharm cannot handle updating packages on the container, like it can with local (virtual) environments. This is not too surprising, since containers shouldn't be considered "long lasting." As you pointed out, installing packages directly in the container is one option. Another is using Pycharm's ssh feature to ssh into the container and the run pip to install your needed packages. However, I think the less temporary solution is to use an image with all the packages you need already installed. Two options here: (1) Either pull from a python image on DockerHub with pre-installed apps, e.g.: use
FROM python:3.8-slim-buster
in your Dockerfile or (2) save your own container with all the packages you want as a new image, by using the docker commit
command, eg. docker commit CONTAINER NEW-IMAGE-TAG
.
Upvotes: 5
Reputation: 936
$ docker exec -it <countainerName/countainerID> bash
$ > pip install package
# hit ctrl+D
$ docker commit <countainerName/countainerID> <imageName:tag>
$ docker-compose up
<imageName:tag>
should be the same of ur current image nameUpvotes: 1