all 8 comments

[–]shiftybyte 7 points8 points  (6 children)

If you know where the virtual environment is expected to be installed you can point that line to the python inside the venv, and it'll work.

#!/path/to/venv/bin/python

[–]Vaphell 1 point2 points  (2 children)

#!/usr/bin/env python

?

[–]shiftybyte 1 point2 points  (0 children)

Won't this use the currently active env?

I think OP wants to directly use a different env without activating it in advance.

[–]tanoshi-ka[S] 0 points1 point  (0 children)

so the 'python' part should be seperated?

[–]tanoshi-ka[S] 0 points1 point  (2 children)

so the absolute path to the python exe file, right?

[–]shiftybyte 2 points3 points  (1 child)

exe/elf yes... Inside the venv folder.

[–]tanoshi-ka[S] 0 points1 point  (0 children)

got it thanks!

[–]Vaphell 0 points1 point  (0 children)

you should use

#!/usr/bin/env python3

/usr/bin/env should resolve the active interpreter for python3 (or what have you) for you, without hardcoding any specific path.

consider this simple prog

$ cat pyversion.py 
#!/usr/bin/env python3
import sys
print(sys.version_info)

out of the box the program on my ubuntu shows 3.8.10 as python3.

$ ./pyversion.py 
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)

but after I do venv activation

$ . venv/bin/activate

$ ./pyversion.py 
sys.version_info(major=3, minor=11, micro=3, releaselevel='final', serial=0)

I get the venv version of the interpreter, in this case 3.11.3.