python-virtualenvwrapper / virtualenvwrapper

Other
128 stars 18 forks source link

lssitepackages fails - Python 3.12 'distutils' removed #78

Closed kwadsten closed 10 months ago

kwadsten commented 1 year ago

Python 3.12 - Of note, the distutils package has been removed from the standard library.

This causes lssitepackages to fail.

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'distutils' ls: : No such file or directory

carltongibson commented 1 year ago

I managed to get this working by reinstalling virtualenvwrapper with Python 3.12.

Specifically, $VIRTUALENVWRAPPER_PYTHON --version needed to be Python 3.12.

I was then able to use the various commands in fresh virtualenvs. (I still have a bit of digging and cleansing to do to my shell environment to make 100% of the error conditions: e.g. on one env I see a PY310 reference and a distutils deprecation warning, so I think there's still a wire crossed there.)

Other than hygiene though, I don't think it's a genuine issue per se.

dhellmann commented 1 year ago

Is that 1 line traceback the entire error stack?

carltongibson commented 1 year ago

@dhellmann Remarkably, yes 😅 (I think I've likely got a shell open with it still. I can paste it in full tomorrow.)

dhellmann commented 1 year ago

OK, I think that makes sense given that the command being run is

"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())

And without distutils that's not going to work.

We need a new way to get the location of the standard library directory for the current Python interpreter. It looks like maybe

"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c 'import sysconfig; print(sysconfig.get_path("platstdlib"))'

or

"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c 'import site; print(site.getsitepackages()[0])'

would do it, but I'll need to do a bit of research to see which is preferred. Do you want to give those a try on your system and see if either fixes the problem?

carltongibson commented 1 year ago

Ah, I was looking at the code on main. Is this resolved by 05ccf752512c74d212f746017f240c692f848983 then?

That stack...

% lssitepackages 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'distutils'
ls: : No such file or directory
dhellmann commented 1 year ago

Oh, it is, yes. It looks like I should do a release.

dhellmann commented 10 months ago

I just published 6.0.0.0a5, which should include the fix for this.

kwadsten commented 10 months ago

Thanks!