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!
I solved this problem.Here's a step-by-step guide on how to do it:
Open the Settings in PyCharm. (On macOS, it's PyCharm > Preferences).
Navigate to Project: [Your Project Name] > Python Interpreter in the left-hand menu.
In the left-hand menu of the "Add Python Interpreter" dialog, select Docker Compose.
For Configuration file(s), specify the path to your docker compose.yml file.
For Service, select the service in your Docker Compose configuration where Python is installed.
Click Next.
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.
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
.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.
I took an unnecessarily roundabout way.
RUN uv pip install -r requirements.txt --system
I just needed to install directly to the system.