Why PyCharm can't resolve reference for a remote Docker interpreter?
Answered
Hi, I'm PyCharm 2017.1.4 Pro and macOS 10.11.6.
PyCharm told me "Unresolved reference 'django'. I did install and it's included in my Docker image. I'm able to run my Django project via a remote Docker interpreter. Any idea how to make it work? Otherwise, how can I use code complete? Thanks.
Please sign in to leave a comment.
When can we expect a fix for this?
Normally docker makes it easy to quickly prototype and experiment with ideas by adding packages to a running container before you arrive at a working solution and the final set of packages that you need. Normally you would only re-build the image at that stage. It's really cumbersome to do such quick prototyping if we have to re-build the image every time we want to add or update a package.
Also, a correction to an earlier comment claiming it's pointless to add packages to a container as they get removed when you stop it, this is not true, all data and settings are preserved if you stop your container, as long as you don't remove it. Stopped (but not removed) containers can be listed with docker ps -a and you can restart them with all changes preserved.
>Also, a correction to an earlier comment claiming it's pointless to add packages to a container as they get removed when you stop it, this is not true, all data and settings are preserved if you stop your container, as long as you don't remove it
This is true if you restart the stopped container, but PyCharm creates a new container every time you run the code, and all changes are wiped clean.
Hello,
Still have this problem on one of the projects using docker image as python interpreter:
Modules "sys" and "pycurl" are not found by PyCharm but when using python console via PyCharm both modules easily can be imported
Invalidate cache and restart doesn't help as well as re-setting up interpreter.
I have the same problem with module "sys" on another project and both projects are built with the same base image: python:
3.5-slim-stretch
Same here, on Mac OS X and Docker dependencies aren't resolved. And like all people here the "plus" button to add more Interpreters paths does nothing.
I'm evaluating to move from the Community version to the Professional version but this bug is preventing me to make the subscription.
In my case it was non root permissions in docker container that I ran python interpreter. PyCharm tries to
and fails so some of the packages remain unrecognized. Changing user to root for the docker image I use as runtime environment solved the problem.
Thank you Eduard, I did already tried that but does not work for me unfortunately :-(
I'm having the same issue, and none of it is working. No users are created (everything is running root).
When I click to refresh the interpreter paths everything stays the same in the package list. At this point I need to manually rebuild the image with every single module import.
What reason could there be to not be able to update the packages in the project interpreter?
- When I restart and clear cache it doesn't work
- When I hit the refresh button below it doesn't work
- My "plus" button in my project interpreter is gray (is this an indicator of what? That I don't have the correct permissions?)
To be clear, the plus button I am missing is here:
@Austincollinpena
> My "plus" button in my project interpreter is gray (is this an indicator of what? That I don't have the correct permissions?)
No, installation of packages for remote interpreter is blocked here, because this is not a correct way to install packages in docker container. The correct way is to install them via Dockerfile. If you install packages in the running container, they'll get removed anyway on the container restart.
Andrey Resler
Okay, but my problem stands. If I run a pip install within my container, I can't use the module until I rebuild the docker image. This feels like a bug.
What version do you use? The issue from the OP post should be fixed in the latest version 2019.3.1
Andrey Resler
I was using 2019.3 but I'm updating to 2019.3.1 and will update. Thank you for that pointer!
Andrey Resler
Still does not work for me
I suggest submitting a support ticket https://intellij-support.jetbrains.com/hc/en-us/?pycharm
Please reproduce the issue in a minimal project, zip and upload it as an example, along with idea.log file (https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files)
Still having this issue. When docker is set as the interpreter, pycharm continues to warn me with "package requirements are not satisfied". I've tried all of the tips mentioned above to no success. Is there a way to tell pycharm that requirements.txt has all of the packages it needs, and they will be installed next time the image is built?
Using Pycharm 2020.1.1
Still does not work for me.
Using Pycharm 2020.1.1
All recomendations:
- Invalidate cache
- Show early version
- Reload path
- Delete and recreate
Not work.
:(
I use 2020.1.2 and invalidate caches with *File | Invalidate Caches & Restart work for me *?
Since PyCharm refuses to fix this issue, I've found that the best solution is to use venv, and add the venv folder to the dockerignore file and the gitignore file. It is much simpler to use docker build from the command line and ignore any docker tools from within PyCharm.
I also have the same issue with docker on recently bought PyCharm. Tried everything exposed as solutions on support and it never worked.
I have similar problems with folder import which PyCharm marks as "Cannot find declaration to go"
It's also very strange, but even if Pycharm doesn't recognize imports, they working well on `docker-compose build` -> `docker-compose up`
I am also experiencig the same problem, pointing to a docker compose interpreter does list the packages, but editor cannot find any reference, checking the path entries is completely empty and I cannot reload nor add anything (buttons simply don't do anything).
Switching to a local venv installation works as expected, yet I don't want to follow that pattern.
PyCharm version is 2020.2 (Linux Ubuntu 18.04)
For me, my Dockerfile was not set up right and after reading this: https://pythonspeed.com/articles/activate-virtualenv-dockerfile/ ... my Dockerfile is now:
docker-compose.yml is:
For the interpreter, I just used defaults in Pycharm, no special handling, no paths, nothing and editor is fine and debugging works. Here is what Pycharm automatically found for Interpreter Paths:
I think the key is in setting $VIRTUAL_ENV in the Dockerfile and $PATH also.
Hope this helps someone.
This is still broken in 2022.2.1. An easy way to repro is create a docker interpreter from image using jupyter/scipy-notebook:python-3.9.12
Once this pulls down, you'll see all the packages listed as though it was successful, but show interpreter paths comes up empty. If you try use this interpreter for any .py file, you'll find that even import os in unresolved.
Alan Jones I'm having the same problem you are, but a coworker is *not* having any issues at all (and I verified it with a screenshare). I can't see any difference in his setup, though, so I'm baffled as to why it's working for him but not me.
Hi Seth, That's interesting - perhaps it's which underlying distro we're using in WSL (assuming that you're using WSL for docker in windows). I'm using Manjaro, WSL v2, Docker Desktop 4.11.1
Sorry Seth Dillingham, I forgot to tag you in the prior post.
Alan Jones We're on macOS here, but it's interesting that we're having this problem across both platforms.
I did learn that the person on my team for whom it is working correctly is actually on a slightly older version of PyCharm (2021.3.3). Now he's afraid to upgrade, and I don't blame him.
Perhaps what you are experiencing is this issue https://youtrack.jetbrains.com/issue/PY-50970/Introspection-over-Targets-doesnt-work-in-Docker-images-with-a-non-root-user
It's a regression indeed. We raised its priority, I'm sorry for all the inconvenience.
That was indeed the issue on my end. I wound up working around it by just putting "USER root" at the end of my dockerfile for now. Andrey on the support team also suggested
Thanks Sergey Karpov
I faced the same issue as described above: no references, grey "+" in installed packages list, etc. The approach with disabling "python.use.targets.api" helped. Thank you!
I ran into this problem today, and added some notes to the ticket.
I was successful using the workaround. Thanks for prioritizing this fix, Sergey Karpov
FWIW, the overall workflow for remote docker configuration is so much better now.