How to use uv run with Django in a PyCharm Docker environment?

I am developing a Django application using a Docker environment in PyCharm. Until now, I have been using pip for package management, but I am considering using uv to potentially reduce container build times.

I managed to install uv in the Docker container, but I am unsure how to configure PyCharm to start Django development using uv run. It seems that the screen where I typically configure run/debug settings does not have an option for this.

How can I set up uv run in PyCharm for my Django project? If possible, I would like to know the best practices or any alternative solutions for this setup.

Thank you in advance for your help! enter image description here

I solved this problem.Here's a step-by-step guide on how to do it:

  1. Open the Settings in PyCharm. (On macOS, it's PyCharm > Preferences).

  2. Navigate to Project: [Your Project Name] > Python Interpreter in the left-hand menu.

  3. In the left-hand menu of the "Add Python Interpreter" dialog, select Docker Compose.

  4. For Configuration file(s), specify the path to your docker compose.yml file.

  5. For Service, select the service in your Docker Compose configuration where Python is installed.

  6. Click Next.

  7. Here, where you would normally select the system interpreter. But this time you will choose Virtual Environment and click the folder icon on the right.

  8. In the dialog that appears, specify the path to the Python executable inside your Docker container. This is typically something like /path/to/.venv/bin/python.

  9. Then select the interpreter from the dropdown menu.

By configuring the Python interpreter in this way, PyCharm will recognize the Python environment within your Docker container, including the uv installation.

enter image description here

I took an unnecessarily roundabout way.

RUN uv pip install -r requirements.txt --system

I just needed to install directly to the system.

Вернуться на верх