question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python refactor: Sort imports does not work with setuptools 49.2

See original GitHub issue

Environment data

  • VS Code version: 1.47.0
  • Extension version (available under the Extensions sidebar): 2020.6.91350
  • OS and version: linux Ubuntu 20.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
  • Relevant/affected Python packages and their versions: isort
  • Value of the python.languageServer setting: Jedi

Expected behaviour

Calling “Python refactor: Sort imports” from command palette sorts import in active document

Actual behaviour

Nothing happens

Steps to reproduce:

  • install setuptools >= 49.2 in workspace venv
  • launch “Python refactor: Sort imports” from command palette

Logs

Devtools console:

Error: /home/me/work/proj/venv/lib/python3.8/site-packages/setuptools/distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  warnings.warn(

	at i (/home/me/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1)
	at Socket.<anonymous> (/home/me/.vscode/extensions/ms-python.python-2020.6.91350/out/client/extension.js:1)
	at Socket.emit (events.js:203)
	at addChunk (_stream_readable.js:295)
	at readableAddChunk (_stream_readable.js:276)
	at Socket.Readable.push (_stream_readable.js:210)
	at Pipe.onStreamRead (internal/stream_base_commons.js:166)
$onExtensionRuntimeError @ workbench.desktop.main.js:sourcemap:4312

Output pane:

> ~/work/proj/venv/bin/python ~/.vscode/extensions/ms-python.python-2020.6.91350/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.6.91350/pythonFiles/sortImports.py - --diff
cwd: ~/work/proj

This warning comes from isort that is installed in venv, both versions 4.3.21 and 5.0.9 (latest) produce this warning. Downgrading setuptools to <49.2 makes “Sort imports” command to work ok again - and this warning disappears. I believe this should not behave this way since even with the warning isort exit code is 0.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:20

github_iconTop GitHub Comments

5reactions
OutOfFocus4commented, Jul 17, 2020

I ran into this problem.

I was able to “fix” it by editing pythonFiles/sortImports.py

sys.stdin = io.BytesIO(stdin.read())
# End workaround

import setuptools # <— insert this line
import isort.main

isort.main.main()
3reactions
madqueendanycommented, Oct 22, 2020

Removing python.sortImports.path from settings.json fixed the issue for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS Code's "Sort Imports" fails with exception - Stack Overflow
I tried switching the Language Server, but it does not help. Steps to reproduce: Open a python script with multiple import lines in...
Read more >
setuptools 5.6 - PyPI
Easily download, build, install, upgrade, and uninstall Python packages.
Read more >
Changelog — Python 3.8.14 documentation
find_library() now works correctly on macOS 11 Big Sur even if Python is built on an older version of macOS. Previously, when built...
Read more >
vscode isort config 11
... Sort imports does not work with setuptools 49.2 (, Python refactor: Sort imports does ... I was able to “fix” it by...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug:1523 - "[IDEA] Offload work by distributing trivial ebuild maintenance to ... include order problem" status:RESOLVED resolution:OBSOLETE severity:normal ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found