microsoft / vscode-flake8

Linting support for python using the flake8 library.
https://marketplace.visualstudio.com/items?itemName=ms-python.flake8
MIT License
37 stars 30 forks source link

Extension Ignores Configured Paths and Defaults to System Python Causing Startup Failure #252

Closed ipfans closed 7 months ago

ipfans commented 8 months ago

Environment

OS: macOS 14.0 VSCode: 1.84.0 vscode-flake8: 2023.10.0

Description

I'm encountering an issue with the Flake8 extension for VS Code where it seems to ignore the configured Python and Flake8 paths. Despite specifying the paths in the settings, the extension defaults to using its internally bundled Flake8 which relies on the system's default Python 3.12. However, my project uses a virtual environment with Python 3.10, leading to a failure in starting the Flake8 server. The error log is as follows:

2023-11-04 10:54:28.711 [info] Traceback (most recent call last):
  File "/Users/user/.vscode/extensions/ms-python.flake8-2023.10.0/bundled/tool/lsp_server.py", line 65, in <module>
    from pygls import server, uris, workspace
  File "/Users/user/.vscode/extensions/ms-python.flake8-2023.10.0/bundled/libs/pygls/server.py", line 37, in <module>
    from pygls.lsp import ConfigCallbackType, ShowDocumentCallbackType
  File "/Users/user/.vscode/extensions/ms-python.flake8-2023.10.0/bundled/libs/pygls/lsp/__init__.py", line 38, in <module>
    from typeguard import check_type
  File "/Users/user/.vscode/extensions/ms-python.flake8-2023.10.0/bundled/libs/typeguard/__init__.py", line 21, in <module>
    from ._importhook import ImportHookManager as ImportHookManager
  File "/Users/user/.vscode/extensions/ms-python.flake8-2023.10.0/bundled/libs/typeguard/_importhook.py", line 22, in <module>
    from typing_extensions import Buffer
ImportError: cannot import name 'Buffer' from 'typing_extensions' (/Users/user/Developer/projects/api/.venv/lib/python3.10/site-packages/typing_extensions.py)

VSCode Configuration:

{
    "flake8.interpreter": [
        "${workspaceFolder}/.venv/bin/python"
    ],
    "flake8.path": [
        "${workspaceFolder}/.venv/bin/flake8"
    ]
}

All pakcages installed in the venv:

Package                           Version
--------------------------------- ------------
absl-py                           2.0.0
aioboto3                          11.3.0
aiobotocore                       2.6.0
aiofiles                          23.2.1
aiogoogle                         5.5.0
aiohttp                           3.8.4
aioitertools                      0.11.0
aiomysql                          0.2.0
aiosignal                         1.3.1
alembic                           1.11.1
aliyun-python-sdk-alimt           3.2.0
aliyun-python-sdk-core            2.14.0
aliyun-python-sdk-core-v3         2.13.33
aliyun-python-sdk-green           3.6.6
aliyun-python-sdk-green-extension 1.0.0
aliyun-python-sdk-kms             2.16.2
anyio                             4.0.0
app-store-server-library          0.2.1
APScheduler                       3.10.1
asn1                              2.7.0
astunparse                        1.6.3
async-asgi-testclient             1.4.11
async-lru                         2.0.4
async-timeout                     4.0.3
attrs                             23.1.0
autoflake                         2.0.0
Babel                             2.12.1
bcrypt                            4.0.1
beautifulsoup4                    4.12.2
black                             22.12.0
blinker                           1.6.3
boto3                             1.28.17
botocore                          1.31.17
cachetools                        5.3.1
cattrs                            23.1.2
certifi                           2023.7.22
cffi                              1.16.0
charset-normalizer                3.3.1
click                             8.1.7
coverage                          7.0.3
crcmod                            1.7
cryptography                      41.0.4
databases                         0.7.0
deepface                          0.0.79
deprecation                       2.1.0
ecdsa                             0.18.0
enum-compat                       0.0.3
exceptiongroup                    1.1.3
fastapi                           0.100.1
filelock                          3.12.4
fire                              0.5.0
flake8                            6.0.0
flake8-async                      22.11.14
flake8-bugbear                    23.7.10
flake8-comprehensions             3.14.0
Flask                             3.0.0
flatbuffers                       23.5.26
frozenlist                        1.4.0
gast                              0.4.0
gdown                             4.7.1
google-api-core                   1.34.0
google-api-python-client          2.91.0
google-auth                       2.23.3
google-auth-httplib2              0.1.1
google-auth-oauthlib              1.0.0
google-cloud-core                 1.5.0
google-cloud-translate            2.0.1
google-pasta                      0.2.0
googleapis-common-protos          1.61.0
grpcio                            1.59.0
grpcio-status                     1.48.2
gspread                           5.10.0
gunicorn                          21.2.0
h11                               0.14.0
h5py                              3.10.0
hiredis                           2.2.3
httpcore                          0.17.3
httplib2                          0.22.0
httptools                         0.6.1
httpx                             0.24.1
idna                              3.4
imageio                           2.31.6
inapppy                           2.5.2
iniconfig                         2.0.0
iso-639                           0.4.5
iso639                            0.1.4
isort                             5.11.4
itsdangerous                      2.1.2
Jinja2                            3.1.2
jmespath                          0.10.0
keras                             2.13.1
langdetect                        1.0.9
lazy_loader                       0.3
libclang                          16.0.6
loguru                            0.7.0
Mako                              1.2.4
Markdown                          3.5
MarkupSafe                        2.1.3
mccabe                            0.7.0
mtcnn                             0.1.1
multidict                         6.0.4
mypy                              0.991
mypy-extensions                   1.0.0
mysql-connector-python            8.0.33
networkx                          3.2
numpy                             1.24.3
oauth2client                      4.1.3
oauthlib                          3.2.2
opencv-python                     4.8.1.78
opt-einsum                        3.3.0
orjson                            3.9.9
oss2                              2.18.0
packaging                         23.2
pandas                            2.1.1
passlib                           1.7.4
pathspec                          0.11.2
phonenumbers                      8.13.16
Pillow                            10.0.0
pillow-heif                       0.13.0
pip                               23.2.1
platformdirs                      3.11.0
pluggy                            1.3.0
pprintpp                          0.4.0
prometheus-client                 0.17.1
prometheus-fastapi-instrumentator 6.1.0
protobuf                          3.20.3
pyasn1                            0.5.0
pyasn1-modules                    0.3.0
pycodestyle                       2.10.0
pycountry                         22.3.5
pycountry-convert                 0.7.2
pycparser                         2.21
pycryptodome                      3.19.0
pycryptodomex                     3.19.0
pydantic                          1.10.12
pyflakes                          3.0.1
pyi18n-v2                         1.2.1
PyJWT                             2.8.0
PyMySQL                           1.1.0
pyOpenSSL                         23.2.0
pyparsing                         3.1.1
PySocks                           1.7.1
pytest                            7.2.0
pytest-asyncio                    0.20.3
pytest-cov                        4.1.0
pytest-env                        0.8.1
pytest-mock                       3.12.0
python-alipay-sdk                 3.3.0
python-dateutil                   2.8.2
python-dotenv                     1.0.0
python-jose                       3.3.0
python-multipart                  0.0.6
pytz                              2023.3.post1
PyWavelets                        1.4.1
pywe-base                         1.0.9
pywe-decrypt                      1.1.7
pywe-miniapp                      1.1.6
pywe-sign                         1.1.0
pywe-storage                      1.0.1
pywe-utils                        1.0.2
pywe-xml                          1.0.6
PyYAML                            6.0.1
redis                             5.0.0
repoze.lru                        0.7
requests                          2.31.0
requests-oauthlib                 1.3.1
retina-face                       0.0.13
rsa                               4.9
s3transfer                        0.6.2
scikit-image                      0.21.0
scipy                             1.10.1
semver                            3.0.1
setuptools                        68.2.0
six                               1.16.0
sniffio                           1.3.0
soupsieve                         2.5
SQLAlchemy                        1.4.48
sqlalchemy-stubs                  0.4
starlette                         0.27.0
stripe                            6.1.0
tensorboard                       2.13.0
tensorboard-data-server           0.7.2
tensorflow                        2.13.0
tensorflow-estimator              2.13.0
tensorflow-macos                  2.13.0
termcolor                         2.3.0
tifffile                          2023.9.26
tomli                             2.0.1
tonyg-rfc3339                     0.1
tqdm                              4.66.1
typing_extensions                 4.5.0
tzdata                            2023.3
tzlocal                           5.2
ujson                             5.8.0
uritemplate                       4.1.1
urllib3                           1.26.18
uvicorn                           0.23.2
wechatpayv3                       1.2.39
Werkzeug                          3.0.0
wheel                             0.41.2
wrapt                             1.15.0
xmltodict                         0.13.0
yarl                              1.9.2
karthiknadig commented 8 months ago

@ipfans The extension needs some components to run the server which is where it is failing. it is not trying to load flake8 from the bundle, just the server bits. Try updating the typing_extensions to 4.8.0 in your environment.

ipfans commented 8 months ago

Thank you for the heads-up. After updating as you suggested, the issue indeed seems to be resolved. However, this appears to be a hidden piece of knowledge as I couldn't find any hints or documentation about this. The root of the problem also relates to my project's dependencies; an older version of TensorFlow had locked the typing_extensions dependency to version 4.5.0. This means that many developers might unwittingly fail to meet the extension's environmental dependency requirements.