pew-org / pew

A tool to manage multiple virtual environments written in pure python
MIT License
1.17k stars 81 forks source link

"Pew add <path>" puts _virtualenv_path_extensions.pth in current directory instead of site-packages directory on some systems #226

Closed asokoloski-m closed 2 years ago

asokoloski-m commented 2 years ago

I think this is something to do with debian patches for python (see https://stackoverflow.com/questions/28011865/why-cant-my-virtualenv-find-distutils-sysconfig)

Running the command python3 -c 'import distutils; print(distutils.sysconfig.get_python_lib())' (as the sitepackages_dir function in pew.py does) gives an error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'setuptools._distutils' has no attribute 'sysconfig'

But sitepackages_dir does not check for errors, so it just uses the string returned on stdout, which is "", and therefore puts the _virtualenv_path_extensions.pth file in the current directory.

Changing the command to python3 -c 'import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())' seems like an easy fix. But it would probably also make sense to check if the python command succeeded or not and print out any errors, in case anything else goes wrong.

tjanez commented 2 years ago

Fixed in https://github.com/berdario/pew/commit/cf6c2204750d17a0bf2974df4d3263c20ef3ca1d.

asokoloski-m commented 2 years ago

@tjanez thank you very much! I appreciate it.