Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - zsh: command not found: flake8 but flake8 is installed

I'm trying to run the flake8 linter on my python code but I am having some issues.

running pip install gives me this response:

~ pip install flake8                                                                                                                                                                                                                                  
Requirement already satisfied: flake8 in ./Library/Python/2.7/lib/python/site-packages
Requirement already satisfied: enum34; python_version < "3.4" in ./Library/Python/2.7/lib/python/site-packages (from flake8)
Requirement already satisfied: configparser; python_version < "3.2" in ./Library/Python/2.7/lib/python/site-packages (from flake8)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in ./Library/Python/2.7/lib/python/site-packages (from flake8)
Requirement already satisfied: pycodestyle<2.4.0,>=2.0.0 in ./Library/Python/2.7/lib/python/site-packages (from flake8)
Requirement already satisfied: pyflakes<1.6.0,>=1.5.0 in ./Library/Python/2.7/lib/python/site-packages (from flake8)

but then when I try to run it I get this error.

~ flake8 --version                                                                                                                                                                                                                                    
zsh: command not found: flake8

I am using a mac as well if that makes any difference.

Please can anyone help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The flake8 script isn't in your path.

First figure out where it's installed:

pip show -f flake8

You should see the install location, usually something ending in site-packages, and then the list of files - one of which may look like ../../bin/flake8. Apply the relative path to the install location and you'll find the executable's path.

If you're using Homebrew on mac, there's a good chance the executable sits under /usr/local/bin, but in any case you need to add that directory to your PATH (search for "add directory to path in zsh") or specify the full path.

Finally, if the path is in PATH and it still doesn't find it, and you added it to the path just now, consider running rehash which rebuilds zsh's hash of executables in the current PATH.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...