All sys prefix values point to the same location

So as I mentioned in another post, I am trying to work out how to determine if a venv is currently active in a shell.

As I have been reading I see references to testing sys.prefex and sys.exec_prefix as a way to determine this.

Oddly, no matter how I create a venv all of my prefix attributes in sys point to the same path

So if I run this code in a venv

print(sys.base_prefix == sys.prefix)
print(sys.prefix)
print(sys.base_prefix)
print(sys.exec_prefix)
print(sys.base_exec_prefix)

I get

True
/Library/Frameworks/Python.framework/Versions/3.11
/Library/Frameworks/Python.framework/Versions/3.11
/Library/Frameworks/Python.framework/Versions/3.11
/Library/Frameworks/Python.framework/Versions/3.11

I get this result in a venv created in Visual Code, poetry and also doing it manually.

It should, of course, look this the results in this video

https://asciinema.org/a/2VxBZQ0agSDwRNAa2l1QwHMTP

Does anyone have any pointers on where to look in the various config files to see what might be causing this issue?

Thanks

Just a followup. I uninstall poetry and virualvenv and still get the same results.

How do we know that this is not the correct result? In other words how do we know that you really are using a virtual environment?

If it is not already what you are doing, I recommend you run the same code with a command like the following:

path/to/venv/bin/python -c 'import sys; print(sys.base_prefix == sys.prefix); print(sys.prefix); print(sys.base_prefix)'`

I really don’t understand the question or why you’d ask it.

It gives a different result on the command line than it does when I run a python file.

Running it using the path to my venv on the command line gives me

False
/Users/Zac/projects/piplist/.venv
/Library/Frameworks/Python.framework/Versions/3.11

but running a python file from the command line gives me

True
/Library/Frameworks/Python.framework/Versions/3.11
/Library/Frameworks/Python.framework/Versions/3.11

Specifically calling python3 to run the file gives me the result I would expect though

False
/Users/Zac/projects/piplist/.venv
/Library/Frameworks/Python.framework/Versions/3.11

python and python3 are currently pointing at different sources.

I would have found it much easier to follow your cases if they included the full command being run. Something to keep in mind for next time maybe.

So, it seems clear that for the second case no virtual environment is in use. Without knowing what exact command(s) was (were) ran in this case, it is difficult to give advice, as to why the virtual environment is not active.