[PYTHON] py, shebang, venv and me

When three elements continue, I want to make it my syntax.

by the way

When do you use py Launcher while using venv on windows? I use it all the time. I knew about shebang, but It's windows. I thought I didn't have to worry too much, but it wasn't.

For example, if you have such a file

hoge.py


#!/usr/bin/env python
import pandas

Furthermore, suppose that there is such an environment. The default python is plain.

$ py -m venv hogenv
$ . hoge/Scripts/activate
(hogenv) $ pip install -U pip
(hogenv) $ pip install pandas

Then, when I try to execute it, py naturally becomes like this. Will it be? I think it will be.

(hogenv) $ py hoge.py

This will tell you that there is no pandas. Because.

PEP in case of trouble

It's really crap, but I feel like this PEP397 is thankful! Seriously thank you

However, I forgot where I saw it because it wasn't all written (maybe somewhere in the reference)

/usr/bin/env python
/usr/bin/python
/usr/local/bin/python
python

With these guys, the py launcher seems to call the default python interpreter. So I think the reason I was told that I don't have pandas earlier is because I called python, which has nothing in it by default.

Based on

Isn't it okay to start it like this?

(hogenv) $ python hoge.py

If you think only in windows, you have passed the path of the virtual environment to shebang, I think it is possible to start it with the py launcher.

Or do you pull out the shebang?

It doesn't tighten in particular, but this is the end

reference

3. Use Python on Windows Shebang https://www.python.org/dev/peps/pep-0397/

Digression

This was a runny nose image.png

Recommended Posts

py, shebang, venv and me
Python3, venv and Ansible
With me, cp, and Subprocess
python with pyenv and venv
With me, NER and Flair
Various of Tweepy. Ma ♡ and ♡ me ♡
For me: Infrastructure and network notes