简体   繁体   中英

pip installing flake8 in a Python3 virtualenv installs flake8 for python 2.7 on OSX

I'm trying to set atom up correctly, and the linter-flake8 package is annoying me by pointing out syntax errors which aren't there, because it's using a python 2 flake8.

Doubly annoying is that when such an error is pointed out in a file, the rest of the file isn't linted, making finding unused imports that much harder.

I set the executable path in the settings to point to the right binary after pip installing it, but the same errors occur.

$ which python
/Users/asday/.virtualenvs/_/bin/python
$ which pip
/Users/asday/.virtualenvs/_/bin/pip
$ pip install flake8
[...]
$ which flake8
/Users/asday/.virtualenvs/_/bin/flake8
$ python -V
Python 3.5.1
$ pip -V
pip 8.1.2 from /Users/asday/.virtualenvs/_/lib/python3.5/site-packages (python 3.5)
$ flake8 --version
2.5.4 (pep8: 1.7.0, pyflakes: 1.0.0, mccabe: 0.4.0) CPython 2.7.11 on Darwin
$ flake8 .
./test.py:9:14: E901 SyntaxError: invalid syntax

Where test.py is simply:

def f(*args, **kwargs):
    pass


kwargs = {}

f(
    a=1,
    **kwargs,
)

How do I get flake8 to install with the right version of python on OSX?

The problem isn't pip or flake8, it's your PATH variable. What you need to do is python -m flake8 to get it to use the one in your environment.

You could download the flake 8 project from https://pypi.python.org/pypi/flake8 then use

pip install file.whl
This way you can just install it from your local python and it should install as python 3.

对Python 3.x使用pip3 install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM