Mailing List Archive

path to python in venv
I was under the impression that in a venv the python used would be in
the venv's bin dir. But in my venvs I see this in the bin dirs:

lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
/usr/bin/python3

Googling this I read:

The presence of symbolic links like python and python3 in the bin
directory of your virtual environment pointing to the system Python
executable (/usr/bin/python) suggests that the virtual environment was
created using the system Python interpreter rather than a standalone
Python installation.

This can happen if you create a virtual environment using a
system-wide Python interpreter, and the virtual environment inherits
some of the symbolic links or shortcuts from the system Python
installation. In this case, your virtual environment is not fully
isolated because it still relies on the system Python interpreter.

Not sure what this really means, nor how to get python to be in my venv.
--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
> I was under the impression that in a venv the python used would be in
> the venv's bin dir. But in my venvs I see this in the bin dirs:
>
> lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
> lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
> /usr/bin/python3
...
> Not sure what this really means, nor how to get python to be in my venv.

WHy do you want python to be "in your venv"?
--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list
<python-list@python.org> wrote:
>
> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
> > I was under the impression that in a venv the python used would be in
> > the venv's bin dir. But in my venvs I see this in the bin dirs:
> >
> > lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
> > lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
> > /usr/bin/python3
> ...
> > Not sure what this really means, nor how to get python to be in my venv.
>
> WHy do you want python to be "in your venv"?

Isn't that the entire point of a venv? To have a completely self
contained env? So if someone messes with the system python it will not
break code running in the venv.
--
https://mail.python.org/mailman/listinfo/python-list
RE: path to python in venv [ In reply to ]
Hi Larry,
You could just create venv with option '—copies'

For example:
python -m venv -–copies .venv


From: Larry Martell via Python-list
Sent: 27 ???????? 2023 ?. 22:48
To: Jon Ribbens
Cc: python-list@python.org
Subject: Re: path to python in venv

On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list
<python-list@python.org> wrote:
>
> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
> > I was under the impression that in a venv the python used would be in
> > the venv's bin dir. But in my venvs I see this in the bin dirs:
> >
> > lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
> > lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
> > /usr/bin/python3
> ...
> > Not sure what this really means, nor how to get python to be in my venv.
>
> WHy do you want python to be "in your venv"?

Isn't that the entire point of a venv? To have a completely self
contained env? So if someone messes with the system python it will not
break code running in the venv.
--
https://mail.python.org/mailman/listinfo/python-list

--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On Wed, Sep 27, 2023 at 12:53?PM Niktar Lirik <niktarlirik@zohomail.com> wrote:
>
> Hi Larry,
>
> You could just create venv with option '—copies'
>
>
>
> For example:
>
> python -m venv -–copies .venv

Thanks! That is just what I was looking for.

> From: Larry Martell via Python-list
> Sent: 27 ???????? 2023 ?. 22:48
> To: Jon Ribbens
> Cc: python-list@python.org
> Subject: Re: path to python in venv
>
>
>
> On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list
>
> <python-list@python.org> wrote:
>
> >
>
> > On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
>
> > > I was under the impression that in a venv the python used would be in
>
> > > the venv's bin dir. But in my venvs I see this in the bin dirs:
>
> > >
>
> > > lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
>
> > > lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
>
> > > /usr/bin/python3
>
> > ...
>
> > > Not sure what this really means, nor how to get python to be in my venv.
>
> >
>
> > WHy do you want python to be "in your venv"?
>
>
>
> Isn't that the entire point of a venv? To have a completely self
>
> contained env? So if someone messes with the system python it will not
>
> break code running in the venv.
>
> --
>
> https://mail.python.org/mailman/listinfo/python-list
>
>
--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On 9/27/23 13:46, Larry Martell via Python-list wrote:
> On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list
> <python-list@python.org> wrote:
>>
>> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
>>> I was under the impression that in a venv the python used would be in
>>> the venv's bin dir. But in my venvs I see this in the bin dirs:
>>>
>>> lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
>>> lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
>>> /usr/bin/python3
>> ...
>>> Not sure what this really means, nor how to get python to be in my venv.
>>
>> WHy do you want python to be "in your venv"?
>
> Isn't that the entire point of a venv? To have a completely self
> contained env? So if someone messes with the system python it will not
> break code running in the venv.

It can do that, it just turns out the defaults are to not make a
dedicated Python instance, and to not give access to the system site
packages. The venv and virtualenv modules, at least, will let you
override either of those defaults via command-line options at creation time.

Once a year I have virtualenvs break when the new Python version appears
in Fedora, which is irritating, but I take the attitude that virtualenvs
are disposable and (try to) not let it bother me that I forgot to deal
with that ahead of time. It helps if you make sure that a virtualenv
has a record of its dependencies - perhaps a requirements.txt file in
the project it's being used to build, so it's easy to recreate them.


--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
> On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list
><python-list@python.org> wrote:
>> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
>> > I was under the impression that in a venv the python used would be in
>> > the venv's bin dir. But in my venvs I see this in the bin dirs:
>> >
>> > lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
>> > lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
>> > /usr/bin/python3
>> ...
>> > Not sure what this really means, nor how to get python to be in my venv.
>>
>> WHy do you want python to be "in your venv"?
>
> Isn't that the entire point of a venv? To have a completely self
> contained env? So if someone messes with the system python it will not
> break code running in the venv.

The main point of the venv is to isolate the installed packages,
rather than Python itself. I'm a bit surprised your symlinks are
as shown above though - mine link from python to python3.11 to
/usr/bin/python3.11, so it wouldn't change the version of python
used even if I installed a different system python version.
--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On 28/09/2023 09.32, Jon Ribbens via Python-list wrote:
> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
>> On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list
>> <python-list@python.org> wrote:
>>> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
>>>> I was under the impression that in a venv the python used would be in
>>>> the venv's bin dir. But in my venvs I see this in the bin dirs:
>>>>
>>>> lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
>>>> lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
>>>> /usr/bin/python3
>>> ...
>>>> Not sure what this really means, nor how to get python to be in my venv.
>>>
>>> WHy do you want python to be "in your venv"?
>>
>> Isn't that the entire point of a venv? To have a completely self
>> contained env? So if someone messes with the system python it will not
>> break code running in the venv.
>
> The main point of the venv is to isolate the installed packages,
> rather than Python itself. I'm a bit surprised your symlinks are
> as shown above though - mine link from python to python3.11 to
> /usr/bin/python3.11, so it wouldn't change the version of python
> used even if I installed a different system python version.


"venv — Creation of virtual environments"
(https://docs.python.org/3/library/venv.html) starts by saying:

«The venv module supports creating lightweight “virtual environments”,
each with their own independent set of Python packages installed in
their site directories.»

but later expands this with: «Used to contain a specific Python
interpreter...» even though the primary use-case treats the system
interpreter as the "base" Python/environment.

Time for some reading and proving appropriate combinations of options?


Over the years there have been various proposals to enable multiple
versions of Python to exist concurrently on a single machine, notably
Python2 + Python3 - but am failing to recall any official docs on
Python3.n + Python3.m; eg "PEP 554 – Multiple Interpreters in the
Stdlib" (https://peps.python.org/pep-0554/).

That said there's plenty of articles on-line (which may/not feature
venv*) such as "Multiple Python interpreters"
(https://developer.fedoraproject.org/tech/languages/python/multiple-pythons.html)

* although the OP didn't mention an OpSys, one poster did mention
Fedora-Linux...


NB some of this info may be dated - it is some time since conducted this
investigation (and decided not to use venv - apologies!)

Am currently using PyCharm (courtesy of recent teams' conventions) and
it eases both problems (which interpreter, and which
development-environment/activation steps) but in automating 'the boring
stuff' it will be interesting to see if in-future, I notice when the
project is based upon an older system!
FYI
https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-reloading-interpreter-paths.html
(I'd be surprised if the other major tool-sets don't offer something
similar)

Disclaimer: JetBrains sponsor our local PUG-meetings with a door-prize.

--
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv [ In reply to ]
On 2023-09-27 20:32:25 -0000, Jon Ribbens via Python-list wrote:
> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
> > On Wed, Sep 27, 2023 at 12:42?PM Jon Ribbens via Python-list<python-list@python.org> wrote:
> >> On 2023-09-27, Larry Martell <larry.martell@gmail.com> wrote:
> >> > lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
> >> > lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 -> /usr/bin/python3
[...]
> I'm a bit surprised your symlinks are as shown above though - mine
> link from python to python3.11 to /usr/bin/python3.11, so it wouldn't
> change the version of python used even if I installed a different
> system python version.

That's probably because you created the venvs with "python3.11 -m venv ...".
The symlink points to the command you used to create it:

% python3 -m venv venv
% ll venv/bin/python*
lrwxrwxrwx 1 hjp hjp 7 Aug 29 2022 venv/bin/python -> python3*
lrwxrwxrwx 1 hjp hjp 12 Aug 29 2022 venv/bin/python3 -> /bin/python3*
lrwxrwxrwx 1 hjp hjp 7 Aug 29 2022 venv/bin/python3.10 -> python3*

% python3.10 -m venv venv
% ll venv/bin/python*
lrwxrwxrwx 1 hjp hjp 10 Sep 28 00:45 venv/bin/python -> python3.10*
lrwxrwxrwx 1 hjp hjp 10 Sep 28 00:45 venv/bin/python3 -> python3.10*
lrwxrwxrwx 1 hjp hjp 15 Sep 28 00:45 venv/bin/python3.10 -> /bin/python3.10*

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
Re: path to python in venv [ In reply to ]
On 9/27/2023 2:53 PM, Larry Martell via Python-list wrote:
> I was under the impression that in a venv the python used would be in
> the venv's bin dir. But in my venvs I see this in the bin dirs:
>
> lrwxrwxrwx 1 larrymartell larrymartell 7 Sep 27 11:21 python -> python3
> lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 ->
> /usr/bin/python3
>
> Googling this I read:
>
> The presence of symbolic links like python and python3 in the bin
> directory of your virtual environment pointing to the system Python
> executable (/usr/bin/python) suggests that the virtual environment was
> created using the system Python interpreter rather than a standalone
> Python installation.
>
> This can happen if you create a virtual environment using a
> system-wide Python interpreter, and the virtual environment inherits
> some of the symbolic links or shortcuts from the system Python
> installation. In this case, your virtual environment is not fully
> isolated because it still relies on the system Python interpreter.
>
> Not sure what this really means, nor how to get python to be in my venv.

You don't need to "get python to be in my venv". The venv contains its
own Python Lib directory, and whatever site-packages installs you want
for that venv. In essence, the script for launching the venv sets up
the PYTHONPATH variable and some other paths so that Python finds its
files in the venv directories instead of in the usual Python locations.
Setting these paths may involve creating symbolic links and that is all
done for you.

The thing you need to appreciate is that when you create a venv with a
command like this:

<python> -m venv path/to/venv

this will all link back to whatever version of Python you used in place
of <python>. If you invoked it with python3, on Linux you will get
whatever your system runs when you type "python3", which would usually
be the system's Python install. If you want to use some other version
of Python, say python3.10, then just run that one instead when you
create the venv.

--
https://mail.python.org/mailman/listinfo/python-list