python / cpython

The Python programming language
https://www.python.org
Other
64.05k stars 30.64k forks source link

venv can't figure out that it's isolated #127025

Open imperialwool opened 3 weeks ago

imperialwool commented 3 weeks ago

Bug report

Bug description:

I installed python3.13 on my Macbook Pro M1 using Homebrew.

I create venv, activate it and trying to install package. But I'm getting this error: ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

I figured out that I can force pip to think that it's isolated. I just added following line in venv/bin/pip3:

#...
if __name__ == '__main__':
    sys.argv.append("--isolated") # i added this line

It worked.

I don't know exactly where is problem: in pip or in venv. But in latest pip version there is the same error, so maybe it's not pip, idk. Or maybe I did something wrong, or maybe homebrew package is broken, idk.

As I remember, in python3.12 that I also installed using Homebrew there was no such error, everything worked out of box perfectly.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

brettcannon commented 3 weeks ago

What's the pip command you used for doing the package installation?

imperialwool commented 2 weeks ago

Something like pip install orjson, pip install Pillow...

imperialwool commented 2 weeks ago
2024-11-20 14:51:48 2024-11-20 14:52:43

Providing examples.

upd: if needed, can provide venv in archive to download and make own tests

brettcannon commented 2 weeks ago

Best way to test where the problem is would be to put a file in the virtual environment's site-packages, launch Python, and then see if you can import the file. That will tell you if the virtual environment is somehow the cause.

I would also launch pip via venv/bin/python -m pip to make sure there's no weird PATH issue going on here.

But based on what your pip3 file contains, my guess it's Homebrew or pip since virtual environments don't do anything magical when it comes to installing pip and I've never seen that sort of message before. You can also try your own copy of pip to see it that changes things (e.g., download https://bootstrap.pypa.io/pip/pip.pyz and see if running that works; venv/bin/python pip.pyz install orjson).

if needed, can provide venv in archive to download and make own tests

Virtual environments are not portable, so that wouldn't be useful.

imperialwool commented 2 weeks ago

I would also launch pip via venv/bin/python -m pip to make sure there's no weird PATH issue going on here.

Just tried, the same error as I shown. Also tried to use "pip.pyz" as you suggested, also the same error. All paths are ok as venv/bin/python pip.pyz inspect showing.

Best way to test where the problem is would be to put a file in the virtual environment's site-packages, launch Python, and then see if you can import the file. That will tell you if the virtual environment is somehow the cause.

I think I should move or duplicate this issue to pip since packages and venv working as intended. I just did issue here since it worked ok in python3.12, but only in python3.13 it doesn't work (both are from homebrew). I thought that it can be some python error since even latest pip version and even other pips (as you suggested to try) just showing the same message. I can also try to compile python3.13 from source, install pip and see if error is still there.