4

I'm writing a python3 script that is used in a Dockerfile. It is based on the official python:3 docker hub image. I've found that I get mixed results depending on what #! line I use in the script. The generally accepted #!/usr/bin/env python3 actually doesn't work. If I used the /usr/sbin/python3 like is the default on my system, it can't find some imported dependencies that I've done a pip3 install on right above. It seems that /usr/local/bin/python3 is the first python3 in the path inside the container. I'd like the script to run comfortably both inside and outside the container. For now I'm just calling the script with python3 in the Dockerfile and skipping the whole mess.

How do I setup the SheBang for best compatibility?

Josiah
  • 2,666
  • 5
  • 30
  • 40

2 Answers2

0

you need to use this shebang simply:

#!/usr/bin/env python
LinPy
  • 16,987
  • 4
  • 43
  • 57
  • 2
    On many systems that will get you a very dated Python 2. I’d expect the form in the question to be correct. – David Maze Oct 03 '19 at 15:14
  • 1
    this is not answering the OP question, he's correct that this shabang would give him the wrong version of python – Fruch May 24 '20 at 09:30
0

For me it was #!/usr/bin/python3 My docker container's FROM command is python:3.9

I found this out by poking around inside the docker image

docker run --rm -it --entrypoint=/bin/bash name-of-image

I used cd and ls to find the python installation and used that path.

BarryTik
  • 1
  • 1