Interpreter setup in PyCharm on docker compose and python2.7

I try to add interpreter on docker compose in PyCharm 2024.2.4 and got some errors:

Connecting to Docker daemon…
Building Compose service odoo10...
 Container odoo10-redis-1  Running
 Container nginx  Running
 Container odoo10_db  Running
 Container odoo10-odoo10-1  Running
/usr/bin/docker compose -f /home/pc/documents/pyprojects/odoo10/docker-compose.yml up --no-start odoo10
Finished with exit code 0
/usr/bin/docker compose -f /home/pc/documents/pyprojects/odoo10/docker-compose.yml -f /home/pc/.cache/JetBrains/PyCharm2024.2/tmp/docker_compose/docker-compose.override.85.yml run --rm --no-deps odoo10
Finished with exit code 1
-P: not found
python3: not found
/usr/bin/docker compose -f /home/pc/documents/pyprojects/odoo10/docker-compose.yml -f /home/pc/.cache/JetBrains/PyCharm2024.2/tmp/docker_compose/docker-compose.override.6.yml run --rm --no-deps odoo10
Finished with exit code 127

The docker compose file is fine, and I can run it from the terminal or by clicking the trinangle button in PyCharm when I open it. I assume the problem is that the container is using python2.7 (yes, I know it's obsolet, but...) and I need to somehow force pycharm to use python2 for it. Thanks for your help in advance

docker 27.3.1
docker compose 2.29.7

0
2 comments

Hello, 

Python 2.7 is still supported, usually with Docker you need to specify the path to the executable manually after the container is built (hit Next):

Click on the … button, specify the path to the executable and select it from the dropdown list (it won't be selected automatically).

Checked with python:2.7.18 image, works as expected: 

It could happen that either Docker or PyCharm cached something and the interpreter is borked, usually it is fixable by clearing IDE caches, and docker elements related to the project (containers, images, volumes, build caches, docker system prune usually works like a charm) and re-creating the interpreter anew.

If you still see any issues: please share your dockerfile (if the image is not publicly accessible, we'll use any similar instead, so it would be great to know the specs in this case), docker-compose.yml and IDE logs (Help | Collect Logs and Diagnostic Data). You can upload files here and tell us the upload ID so we can find files.

0

Hello Daniil Bogdanov  Thanks for your help

Finally I understood what you mean… I just needed to find python2 path inside the container and add it on the 3rd step!

How could I've been so stupid…

0

Please sign in to leave a comment.