Comments (22)
@eblot For a quick and dirty fix, see my answer above.
First open linter.py
:
PackageResourceViewer: Open Resource > SublimeLinter-flake8 > linter.py
Next, replace,
cmd = ('flake8@python', '*', '-')
with,
cmd = ('flake8', '*', '-')
and that should do it.
from sublimelinter-flake8.
I'm also seeing this behaviour. In my case I get,
SublimeLinter: find_python(version=None, script='flake8', module=None)
SublimeLinter: find_python: default python = /usr/bin/python
SublimeLinter: find_python: available version = {'major': 2, 'minor': 7}
SublimeLinter: find_python: 'flake8' path = /usr/local/bin/flake8
SublimeLinter: find_python: <= ('/usr/bin/python', '/usr/local/bin/flake8', 2, 7)
SublimeLinter: flake8 version query: /usr/bin/python /usr/local/bin/flake8 --version
SublimeLinter: WARNING: no flake8 version could be extracted from:
Traceback (most recent call last):
File "/usr/local/bin/flake8", line 7, in <module>
from flake8.main.cli import main
ImportError: No module named flake8.main.cli
My crude workaround is to replace,
cmd = ('flake8@python', '*', '-')
with,
cmd = ('flake8', '*', '-')
in linter.py
. Then SublimeLinter-flake8 uses the correct version of Python (python3
in my case, since I installed flake8
with pip3
).
from sublimelinter-flake8.
This issue affects me also.
I decided to use the git clone technique to install the old version.
- Using Package Control, remove the SublimeLinter-flake8 package.
- In the SublimeText app data directory (look here), in
Packages/
:git clone https://github.com/SublimeLinter/SublimeLinter-flake8 -b 2.1.0
.
from sublimelinter-flake8.
@asfaltboy you are correct, the default Python in /usr/bin/python
is indeed 2.7, and is the macOS provided Python, which I do not use at all (per se).
And there is nothing in /usr/local/bin/python
. Only python3 exists. You may have pointed me to right direction, I will try to symlink a bit later.
And last, but not least, thank you very much for your support!
EDIT: I made a symlink as follows: ln -s /usr/local/bin/python3 /usr/local/bin/python
and hey presto, linter is back alive! Just trying to test, did something else break ;)
from sublimelinter-flake8.
Seems to be caused by #51
from sublimelinter-flake8.
An example of this issue. I have Python 3.6 installed via Homebrew, and pip-installed flake8 on system level. Sublime major version is 3 and build is 3152.
which python3
/usr/local/bin/python3
which flake8
/usr/local/bin/flake8
Flake8 works perfectly fine from shell.
Trying to load SublimeLinter results, with debug on:
SublimeLinter: find_posix_python: python3 => /usr/local/bin/python3
SublimeLinter: find_python: system python = /usr/local/bin/python3
SublimeLinter: find_python: available version = {'major': 3, 'minor': 6}
SublimeLinter: find_python: <= ('/usr/local/bin/python3', None, 3, 6)
SublimeLinter: sys.path for /usr/local/bin/python3:
/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python36.zip
/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6
/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
/usr/local/lib/python3.6/site-packages
... and a couple of lines later:
SublimeLinter: find_python(version=None, script='flake8', module=None)
SublimeLinter: find_python: default python = /usr/bin/python
SublimeLinter: find_python: available version = {'major': 2, 'minor': 7}
SublimeLinter: find_python: 'flake8' path = /usr/local/bin/flake8
SublimeLinter: find_python: <= ('/usr/bin/python', '/usr/local/bin/flake8', 2, 7)
SublimeLinter: flake8 version query: /usr/bin/python /usr/local/bin/flake8 --version
SublimeLinter: WARNING: no flake8 version could be extracted from:
Traceback (most recent call last):
File "/usr/local/bin/flake8", line 7, in <module>
from flake8.main.cli import main
ImportError: No module named flake8.main.cli
No matter the linter settings, everything seems to default to this default python
in the end. I hope this helps to resolve the issue.
There's more discussion on this issue here: #51
from sublimelinter-flake8.
@jaraco I edited the package manually the way @joeycarter suggests above. Everything works again and I can continue my actual work.
With my understanding there might be something wrong with the way SublimeLinter resolves the @python executable path, regardless of the linter settings.
from sublimelinter-flake8.
@janikarh thanks for the info! According to your comments, you have flake8 installed in your python3 env, which is not your default python (at least /usr/bin/python seems to be 2.7). Executing python uses the python executable only, not python2 or python3, so whatever version it is (normally a symlink), is the env that will be used.
Do you have a /usr/local/bin/python
? If so, what does it point to?
Hmm ... it seems that (at the very least) the resolution order of python versions differs when we log SublimeLinter: find_python: default python = /usr/bin/python
vs the initial SublimeLinter: find_python: system python = /usr/local/bin/python3
. This may be the real core of your issue. Could it be that you use an plugin that modifies environment, such as Environment Settings ? If so, this plugin it could be modifying paths, placing /usr/bin/
before /usr/local/bin
which is what you intended, because remember, the first python found is used to execute flake8 --version
.
Also, I haven't followed the code for using "executable" setting so for simplicity sake, I'd remove that.
P.s.: I'm not affiliate or even a contributor to SublimeLinter, I just feel that I should help everyone out since I'm a fan of PR #51 and feel responsible for bumping it up into being merged.
from sublimelinter-flake8.
@mandeep thanks for the detailed report, can you also attach your sublimelinter settings
and related project-settings
or .sublimelinterrc
contents? I would put my money that in your case, the environment in sublime differs from your command line. I used the following patch to SublimeLinter when debugging the issue reproduced locally.
lint/util.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lint/util.py b/lint/util.py
index bdd6613..b75beb0 100644
--- a/lint/util.py
+++ b/lint/util.py
@@ -1278,6 +1278,15 @@ def popen(cmd, stdout=None, stderr=None, output_stream=STREAM_BOTH, env=None, ex
env.update(extra_env)
try:
+ from . import persist
+ persist.debug('{} {} {} {} {} {}'.format(
+ cmd,
+ subprocess.PIPE,
+ stdout,
+ stderr,
+ info,
+ env
+ ))
return subprocess.Popen(
cmd,
stdin=subprocess.PIPE,
It helped me see which parameters are responsible for properly detecting the package, vs causing an error. I bet if you have the same parameters in shell, it will fail just the same.
from sublimelinter-flake8.
On my system, the default python
is also python2.7
, in which flake8
is not installed. What's awkward is that with this latest patch, SublimeLinter.flake8 is expecting flake8
to be installed in that default python installation. That seems to be a mistake, especially given that the shebang for flake8
clearly points to another Python.
bash-3.2$ which python
/usr/bin/python
bash-3.2$ head -n 1 $(which flake8)
#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
The mistake I think is that this plugin is requiring the environment to be massaged to ensure that python
is always the desired target executable, a change which could potentially affect many other applications.
Prior to #51, however, everything seemed to work fine. Contrary to the claim in that ticket:
Unless cmd is defined with @python, SublimeLinter will always use ST's
python, which is version 3.
That can't be the case, because with 2.1.0, the flake8
processing happens and happens with Python 3.6 syntax checks (e.g. recognizing "f-strings"), even though the ST python is Python 3.3 (or similar).
In my opinion, the previous behavior was correct and honored the behavior one would find with the command line instead of explicitly selecting a (possibly wrong) interpreter.
from sublimelinter-flake8.
@jaraco regarding the shebang, that's a very correct observation, however I don't believe SublimeLinter is "shebang aware"; that is, it does not parse the linter script to figure out the right python version. Maybe that would be a nice solution, at least for "POSIX systems".
As far as I know, the version of python used to run flake8 is used to "enforce" syntax for a given version. I.e if your code 2.7 you WANT f-strings
usage to be caught by the linter and a syntax-error displayed. It is also noted in a number of places in the docs, such as in this quickstart note.
The discussion on what is the right (or wrong) way to determine python version should be done in SublimeLinter/issues rather than this plugin, I have a hunch that this was heavily discussed before, just by the amount of issues raised here... That does not mean we can't improve the detection to cover more cases, but it's something that really should be discussed with the maintainers of SublimeLinter.
@janikarh sure thing, and good luck!
from sublimelinter-flake8.
Here is the sublimelinter settings. I don't use a project file or sublimelinterrc.
{
"user": {
"debug": true,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "background",
"linters": {
"flake8": {
"@disable": false,
"args": [],
"builtins": "",
"excludes": [],
"executable": "",
"ignore": "",
"jobs": "1",
"max-complexity": -1,
"max-line-length": null,
"select": "",
"show-code": false
},
"gcc": {
"@disable": false,
"args": [],
"excludes": [],
"extra_flags": "-Wextra -Wformat=2 -Wshadow -Wundef -Wpointer-arith -Wcast-align -Wstrict-prototypes -std=c11"
},
"mlint": {
"@disable": false,
"args": [],
"excludes": []
},
"rust": {
"@disable": true,
"args": [],
"crate-root": null,
"excludes": [],
"use-cargo": true,
"use-cargo-check": true,
"use-crate-root": false
},
"shellcheck": {
"@disable": true,
"args": [],
"exclude": "",
"excludes": []
}
},
"mark_style": "squiggly underline",
"no_column_highlights_line": false,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []
},
"python_paths": {
"linux": [],
"osx": [],
"windows": []
},
"rc_search_limit": 3,
"shell_timeout": 10,
"show_errors_on_save": false,
"show_marks_in_minimap": true,
"syntax_map": {
"html (django)": "html",
"html (rails)": "html",
"html 5": "html",
"javascript (babel)": "javascript",
"magicpython": "python",
"php": "html",
"python django": "python",
"pythonimproved": "python"
},
"tooltip_fontsize": "1rem",
"tooltip_theme": "Packages/SublimeLinter/tooltip-themes/Default/Default.tooltip-theme",
"tooltip_theme_excludes": [],
"tooltips": false,
"warning_color": "DDB700",
"wrap_find": true
}
}
from sublimelinter-flake8.
@mandeep Doesn't seem like you customized your settings, that's great. Since you don't specify any locations, SublimeLinter will rely on Sublime's environment when executing flake8 --version
, with this particular env, it fails.
Try my SublimeLinter debug patch above to see exactly which env variables are in sublime, and compare these to the ones set in your shell, the difference should be the cause of the error.
from sublimelinter-flake8.
Hi all,
Is there an easy, simple way to tell flake8 to revert back to use Python3. I do not mind if it is dirty, I do not really mind which solution is better or worse, I just like to get things to work as it used to be before Package Manager upgraded it, at least till someone comes with the right clean and lean solution.
Thanks in advance.
from sublimelinter-flake8.
@eblot have you configured your linter and looked at the troubleshooting docs?
I've mentioned the simplest workaround I know of above: use paths.
To always use python3, set "@python": 3
globally.
from sublimelinter-flake8.
@asfaltboy I have added
"@python": 3,
"paths": {
"osx": ["/usr/local/opt/python3/bin/python3.5"],
},
to my Preferences.sublime-settings file,
but /usr/local/bin/flake8 keeps being launched from Python 2.7.10 since the upgrade.
from sublimelinter-flake8.
Set @python to /usr/local/opt/python3/bin/python
or whatever points to your good python?
from sublimelinter-flake8.
@joeycarter Thanks a lot, works like a charm. You save my day :-)
from sublimelinter-flake8.
@eblot Glad you resolved your issue 😄 ! As to your settings, I believe it will also work if you change:
"osx": ["/usr/local/opt/python3/bin/python3.5"],
to
"osx": ["/usr/local/opt/python3/bin"],
from sublimelinter-flake8.
@groteworld
This is still broken after the update to SublimeLinter 3.10.3, which was supposedly going to fix the issue.
I don't understand the issue, but I do know that @joeycarter 's fix of modifying linter.py
worked. Perhaps you guys ought to release a version that uses cmd = ('flake8', '*', '-')
instead of cmd = ('flake8@python', '*', '-')
, i.e. use the quick and dirty fix.
from sublimelinter-flake8.
I have my PR #57 ready, which needs some testing folks.
from sublimelinter-flake8.
This has been closed in #57
from sublimelinter-flake8.
Related Issues (20)
- recent update triggers ImportError of configparser module HOT 4
- Does not work at all in Sublime 3.1.1 HOT 3
- F401 handling trips on star imports HOT 3
- No linting errors reported but there should be
- Can't find this package in Package control HOT 3
- .flake8 in a subdirectory HOT 4
- can get E,W type errors, but no F type errors HOT 7
- Error: 'selector' is mandatory in 'cls.defaults' HOT 3
- Is --per-file-ignores supported for flake8 >= 3.7.0? HOT 11
- Package not showing in packaging control anymore HOT 1
- Shows E251 for function definitions having type annotations HOT 2
- Args seem to be getting ignored HOT 1
- Extend "E501 line too long" match till end of line HOT 1
- AttributeError: 'int' object has no attribute 'rstrip' HOT 3
- W type errors not showing HOT 1
- SublimeText 4 Support HOT 2
- Using per-file-ignores argument in settings causes an error HOT 4
- TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper. Why extra " -" is being added after `flake8 --format default`? HOT 6
- plugin_host-3.3 has exited unexpectedly HOT 6
- List unpack operator in assignment triggers false positive HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sublimelinter-flake8.