“ModuleNotFoundError:没有名为‘pycodestyle’的模块”

问题描述

我已经在我的 mac 上使用

在同一路径安装了pycodestyle
pip install pycodestyle

但是当我检查它的版本时,我得到-

    "pycodestyle" --version
Traceback (most recent call last):
  File "/Users/shashwatkhilar/tools/bin/pycodestyle",line 6,in <module>
    from pycodestyle import _main
ModuleNotFoundError: No module named 'pycodestyle'

解决方法

  1. 创建项目目录demo
  2. 将目录切换到项目目录
  3. 创建一个虚拟环境myenv
  4. 激活虚拟环境。
  5. 安装pycodestyle
mkdir demo
cd demo
python3 -m venv myen
source myenv/bin/activate
pip install pycodestyle

使用这些命令检查是否已安装

pip freeze

pycodestyle --version
,

由于您使用的是 mac。我认为你应该至少有两个版本的 python,这个 pip install 是用另一个 python 安装的。你可以试试

pip3 install pycodestyle

如果这不起作用,请尝试找到您要使用的正确版本并设置别名

alias python=/usr/local/bin/python3
,

在 Mac 上,pip 是指旧版本的 Python。如果您想使用 Python 3,请使用 pip3 命令。