On Tue, Mar 24, 2020 at 10:22:28AM +1100, Steven D'Aprano <st...@pearwood.info> 
wrote:
> On Mon, Mar 23, 2020 at 08:09:57PM +0100, Oleg Broytman wrote:
> > On Mon, Mar 23, 2020 at 05:59:41PM -0000, Fr??d??ric De Jaeger 
> > <fdejae...@novaquark.com> wrote:
> > > The issue is:  There is no reliable way to launch a python script.
> > > 
> > > The command:
> > > 
> > >      python myscript.py
> > > 
> > > launches python3 on windows and python2 on 99% of the unix market.
> > 
> > Create and activate a virtual environment (``virtualenv`` or
> > ``python -m venv``) and always use ``python myscript.py``.
> 
> Won't that create a virtual environment using Python3 on Windows and 
> using Python2 most other places, which is exactly the problem Fred is 
> having?

Depends on how literally one reads ``python -m venv``. Just for example:
I run a lot of tests for my libraries locally under all possible Pythons
so I have all versions -- 2.7 and 3.4+ up to 3.8 (soon to add 3.9) -- so
I create all possible venvs; I run Windows inside VirtualBox emulator
where I have even more Pythons -- 32-bit and 64-bit.

When I need a particular version I create, activate and populate a
specific venv.

> Doesn't using a virtual environment require the caller to explicitly 
> activate it, otherwise they will still get the system (global) Python? 

Yes. I don't think it's a major problem. Activating a venv once (for a
terminal) is surely simpler than remembering the difference between
``python`` and ``python3``, ``pip`` and ``pip3``, ``pip2.7``, ``pip3.5``
and ``pip3.6``.

> If Fred successfully creates a virtualenv using the correct version of 
> Python, how does that help him when he distributes his script across his 
> organisation, and to his users? Some of them may not have access to 
> Fred's virtualenv.

Python virtualenv is a development tool but not a distribution or
a deployment tool. To distribute a script one is recommended to build a
wheel and allow ``pip`` to configure the script to use a proper Python
version.

Even better (but harder) distribution/deployment tools are freezers --
cx_Freeze/PyInstaller/pyapp/pyexe. They bundle the required Python and a
subset of the standard library with the script.

Even better (but even more harder) are OS-specific installers --
RPM, deb, w32 installers.

> These are not rhetorical questions. I'm not a heavy virtualenv user and 
> I may not understand it fully.
> -- 
> Steven

Oleg.
-- 
    Oleg Broytman            https://phdru.name/            p...@phdru.name
           Programmers don't die, they just GOSUB without RETURN.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HO45ZXZ6XHPZNDC2I3QRCUVGKTP5ME66/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to