0

I have a Python application that I am developing in PyCharm Professional 2022.1.2 on Windows. I am using Poetry to manage my application and all package dependencies are listed in pyproject.toml.

I would like to debug my application in Linux in a Docker container.

I've successfully set up a Remote Docker Interpreter based on documentation from JetBrains but when I try to run my application with it, I get this error:

70a53fea2bae:python -u /opt/project/myapp/cli/main.py serve 
Traceback (most recent call last):
  File "/opt/project/myapp/cli/main.py", line 7, in <module>
    from myapp.dashboard import serve_dashboard
  File "/opt/project/myapp/__init__.py", line 1, in <module>
    from myapp.pipeline.api.data_reader import ExperimentReader
  File "/opt/project/myapp/pipeline/api/data_reader.py", line 7, in <module>
    from pandas import DataFrame
ModuleNotFoundError: No module named 'pandas'

Process finished with exit code 1

This makes me think that my application's package dependencies have not been installed inside the container.

How can I get PyCharm to install my dependencies (poetry install presumably?) before running my app?

urig
  • 16,016
  • 26
  • 115
  • 184
  • What does your docker file look like? – Jortega Jun 14 '22 at 13:04
  • @Jortega I'm not using a `Dockerfile`. I pointed PyCharm to public image: `python:3.9.13-buster`. That only contains Debian Buster + Python. – urig Jun 14 '22 at 13:09
  • So how are you installing the python modules in the docker container then? Create a docker file that points to the image python:3.9.13-buster. – Jortega Jun 14 '22 at 16:19
  • @Jortega Thanks. I'm trying to avoid having to author a Dockerfile that installs the packages for me. I'm looking for a solution that will install them for me, a bit like how PyCharm makes my code available in the container automatically. Not sure if PyCharm does this or if it's possible TBH. – urig Jun 15 '22 at 12:28
  • Interesting idea... You could push your own docker image to the docker repository. – Jortega Jun 15 '22 at 14:34

1 Answers1

1

The image you're using python:3.9.13-buster is delivered without your extra dependencies. It is like a raw python installation on your local machine.

If you want to enhance it with your custom dependencies, you need to create a Dockerfile which instructs docker to build a new image based on python:3.9.13-buster but with your extra dependencies (pandas) preinstalled.

I'd suggest starting with this tutorial to get familiar with how docker works and how to define custom images using Dockerfile and how to build & use them.

PS Here is some SO answer with example how such Dockerfile for image which installs dependencies defined using poetry's pyproject.toml may look like: https://stackoverflow.com/a/71786211/6082882 but again I'd suggest starting with learning docker fundamentals.

Piotr Szyma
  • 179
  • 1
  • 3
  • Thank you for your answer. However, I am quite familiar with how docker works etc. The expectation in my question is that similar to how PyCharm makes y code automatically available to the running container, it (PyCharm) should also make dependencies available there. Should I learn that this is not within PyCharm's current functionality, I will follow up on your suggestion to implement through a Dockerfile myself. – urig Jun 14 '22 at 13:37