ModuleNotFoundError: No module named 'distutils.core'
ModuleNotFoundError: No module named 'distutils.core'
我最近从 Ubuntu 18.04
升级到 19.04
,其中有 python 3.7
。但是我使用 Python 3.6
.
从事许多项目
现在,当我尝试在 PyCharm 中使用 Python 36
创建 virtualenv
时,它会引发:
ModuleNotFoundError: No module named 'distutils.core'
我不知道该怎么办。
我尝试安装 distutils:
milano@milano-PC:~$ sudo apt-get install python3-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-distutils is already the newest version (3.7.3-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
但是如你所见,我有最新版本。
你知道要做什么吗?
Python 基本解释器确实需要一些额外的模块。那些没有安装例如Ubuntu 默认为 18.04。
要解决这个问题,我们需要先找到您 运行 的 python 版本。如果您的系统上只安装了一个 python 版本(并且您确定),则可以跳过此步骤。
# from your project interpreter run
# your_project_python --version
$ python3 --version
Python 3.7.8
您现在需要为这个精确的 python 解释器安装 distutils。
所以这个例子的解决方案是:
sudo apt install python3.7-distutils
# sudo apt install python3-distutils # would just update default python intrpreter
请记住,任何命令行中的 运行 python 都可能是 python 的另一个版本,那么您的项目就是 运行!
如果这没有帮助,请寻找以下可能性。这将为您带来从命令行中的别名解析的二进制文件。
$ which python
/usr/bin/python
$ ls -lach /usr/bin/python
lrwxrwxrwx 1 root root 9 Jun 8 2018 /usr/bin/python -> python2.7
对于这个答案,我还合并、总结、排序和解释了 Neo、Andrei、Mostafa 和 Wolfgang 提供的一些内容。
作为巫师学徒的旁注:您可能想卸载 python 解释器。对于根本不需要的建议解决方案!但是,请记住,您的整个 OS 都依赖于一个 python 解释器。所以这个默认的,你不想卸载。如果你这样做,你会在寻找桌面任务栏和基本上所有东西时陷入困境。
其他案例
这发生在我的 python3.7 安装上,但在我将 ubuntu 升级到 20.04
后,我的主要 python3 没有发生
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.7
如果我在 ubuntu 20.04(在我的例子中是 kubuntu 20.04 上有多个版本的 python3(等 3.8 作为主要版本和来自 ppa 的 3.9:deadsnakes/ppa) ) 它不起作用
sudo apt install python3-distutils
那么对我有用
sudo apt install python3.9-distutils
对我来说,问题是通过专门使用 python3 解决的,因此确保使用了 python3.8
python --version
Python 3.7.5
python3 --version
Python 3.8.5
目前,我正在使用 ubuntu 18.04
和 python 3.6.9
。 运行 以下命令 mentioned here:
后我的问题得到解决
sudo apt-get install python3-dev
更多详细信息:需要 python 中的某些模块,但未安装。
尝试在 pipenv 中为 python 3.9 版安装 python3.9-distutils 后,我仍然收到错误消息。
正如我注意到的 here python3.9-distutils 与该软件包的早期版本冲突,无法在 Ubuntu18.04 上安装。
我继续使用 python_version = "3.6"
和 pipenv 否则 $ pipenv install
将采用 python 的最高版本并将其写入 Pipfile
和 Pipfile.lock
.
$ pipenv --rm #To remove the old environment
$ rm Pipfile* #Remove both Pipfiles
$ pipenv install --python 3.6
我最近从 Ubuntu 18.04
升级到 19.04
,其中有 python 3.7
。但是我使用 Python 3.6
.
现在,当我尝试在 PyCharm 中使用 Python 36
创建 virtualenv
时,它会引发:
ModuleNotFoundError: No module named 'distutils.core'
我不知道该怎么办。
我尝试安装 distutils:
milano@milano-PC:~$ sudo apt-get install python3-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-distutils is already the newest version (3.7.3-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
但是如你所见,我有最新版本。
你知道要做什么吗?
Python 基本解释器确实需要一些额外的模块。那些没有安装例如Ubuntu 默认为 18.04。
要解决这个问题,我们需要先找到您 运行 的 python 版本。如果您的系统上只安装了一个 python 版本(并且您确定),则可以跳过此步骤。
# from your project interpreter run
# your_project_python --version
$ python3 --version
Python 3.7.8
您现在需要为这个精确的 python 解释器安装 distutils。 所以这个例子的解决方案是:
sudo apt install python3.7-distutils
# sudo apt install python3-distutils # would just update default python intrpreter
请记住,任何命令行中的 运行 python 都可能是 python 的另一个版本,那么您的项目就是 运行!
如果这没有帮助,请寻找以下可能性。这将为您带来从命令行中的别名解析的二进制文件。
$ which python
/usr/bin/python
$ ls -lach /usr/bin/python
lrwxrwxrwx 1 root root 9 Jun 8 2018 /usr/bin/python -> python2.7
对于这个答案,我还合并、总结、排序和解释了 Neo、Andrei、Mostafa 和 Wolfgang 提供的一些内容。
作为巫师学徒的旁注:您可能想卸载 python 解释器。对于根本不需要的建议解决方案!但是,请记住,您的整个 OS 都依赖于一个 python 解释器。所以这个默认的,你不想卸载。如果你这样做,你会在寻找桌面任务栏和基本上所有东西时陷入困境。
其他案例
这发生在我的 python3.7 安装上,但在我将 ubuntu 升级到 20.04
后,我的主要 python3 没有发生sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.7
如果我在 ubuntu 20.04(在我的例子中是 kubuntu 20.04 上有多个版本的 python3(等 3.8 作为主要版本和来自 ppa 的 3.9:deadsnakes/ppa) ) 它不起作用
sudo apt install python3-distutils
那么对我有用
sudo apt install python3.9-distutils
对我来说,问题是通过专门使用 python3 解决的,因此确保使用了 python3.8
python --version
Python 3.7.5
python3 --version
Python 3.8.5
目前,我正在使用 ubuntu 18.04
和 python 3.6.9
。 运行 以下命令 mentioned here:
sudo apt-get install python3-dev
更多详细信息:需要 python 中的某些模块,但未安装。
尝试在 pipenv 中为 python 3.9 版安装 python3.9-distutils 后,我仍然收到错误消息。 正如我注意到的 here python3.9-distutils 与该软件包的早期版本冲突,无法在 Ubuntu18.04 上安装。
我继续使用 python_version = "3.6"
和 pipenv 否则 $ pipenv install
将采用 python 的最高版本并将其写入 Pipfile
和 Pipfile.lock
.
$ pipenv --rm #To remove the old environment
$ rm Pipfile* #Remove both Pipfiles
$ pipenv install --python 3.6