Cannot create remote interpreter for fastapi app
Hi Team, I have problem with creating remote docker compose interpreter in fastapi project. Next to my company's project I created a new one, minimum sample and problem is the same.
After creating interpreter, I see all installed apps on list, but all of them all underlined red in imports and I get message:
failed to run generator3/__main__.py for /usr/local/bin/python3, exit code 2, stderr: ----- Volume "fastapiproject_14572467-5343-4023-9c55-b14c386f1083" Creating Volume "fastapiproject_14572467-5343-4023-9c55-b14c386f1083" Created usage: generator3 [-h] [-d PATH] [-s PATH_LIST] [--name-pattern PATTERN] [--builtins-only] [--state-file PATH] [--init-state-file] [-q] [-v] [-V] [-S] [-z ARCHIVE] [-u ARCHIVE] [-c MODULES] [-p] [mod_name] [mod_path] generator3: error: argument --state-file: can't open '/tmp/a53e9675-6baa-46a7-8d57-186a4190e5bf/.state.json': [Errno 2] No such file or directory: '/tmp/a53e9675-6baa-46a7-8d57-186a4190e5bf/.state.json' -----
Test, server, everything works in console. Can you help?
Docker version 24.0.2, Docker Compose version v2.19.0, Ubuntu 22.04.2 LTS, PyCharm 2023.1.3 (Professional Edition)
Please sign in to leave a comment.
Please upload our Dockerfile, docker-compose.yml, and PyCharm logs (Help | Collect Logs and Diagnostic Data) here: https://uploads.services.jetbrains.com/ and tell us the upload ID, so we can check what's going on here.
Hello,
thanks for fast response. Upload id is 2023_06_28_zrDLxLEDNT3cazb4mktNv3. I cannot send my company project, this is sample one. But behavior is the same.
Thank you very much for providing the required data. I've checked the project and the docker setup and I think I got how to resolve the problem.
When you are creating a docker-compose interpreter you can select what python executable PyCharm should use from the docker container:
By default, PyCharm suggests system interpreter in the default directory and usually it's completely ok since container is built specifically for the application and using system interpreter is convenient. In your case, you are creating a virtual environment and installing packages there. So, when you are creating a docker-compose interpreter, you need to select Virtual environment:
Click on the 3 dots button and enter the path to python executable in your virtual environment:
And then select it from the dropdown list:
Then PyCharm will be using this venv instead of system interpreter, no import errors were observed and everything works as expected.
Hi Daniil. Thanks for the solution, but it does not work as it should. This path is shown as invalid (tried .../bin/python3 as well)
After click "Create" Pycharm sees all packages in interpreter and installed apps, but they are underlined red in editor. Whole python is "invisible" simple "print" is underlined.
Whats more, such simple server config:
works, I can make api call and get response. But it is totally impossible to work in editor :
Sorry, this is not my first project in Pycharm and always everything worked great. I have no idea what is going on :(
One more thing. As a workaround I downgraded PyCharm to 2022.1.4 and it works.
Hi Daniil Bogdanov. I've checked on latest version ( 2023.1.4 from 11.07.2023). There is no improvement. Any update on your side?
Hi Daniil Bogdanov. On latest version 2023.2 everything works fine. Thanks for your help!
Unfortunately no