简体   繁体   English

pip在Python3中安装flake8 virtualenv在OSX上为python 2.7安装flake8

[英]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. 我正在尝试正确设置原子,而linter-flake8包通过指出不存在的语法错误使我很烦,因为它使用的是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. 我在pip安装后将设置中的可执行路径设置为指向正确的二进制文件,但是会发生相同的错误。

$ 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: 其中test.py只是:

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? 如何在OSX上使用正确版本的python安装flake8?

The problem isn't pip or flake8, it's your PATH variable. 问题不是pip或flake8,而是您的PATH变量。 What you need to do is python -m flake8 to get it to use the one in your environment. 您需要做的是python -m flake8使其在您的环境中使用。

You could download the flake 8 project from https://pypi.python.org/pypi/flake8 then use 您可以从https://pypi.python.org/pypi/flake8下载flake 8项目,然后使用

pip install file.whl
This way you can just install it from your local python and it should install as python 3. 这样,您可以从本地python安装它,它应该以python 3安装。

对Python 3.x使用pip3 install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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