我最近从 Ubuntu 18.04
升级到具有 python 3.7
的 19.04
。但我使用 Python 3.6
处理了许多项目。
现在,当我尝试在 PyCharm 中使用 Python 36
创建一个 virtualenv
时,它会引发:
ModuleNotFoundError: No module named 'distutils.core'
https://i.stack.imgur.com/kKMZC.png
我不知道该怎么办。
我尝试安装 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 解释器。对于根本没有必要提出的解决方案!但是,请记住,您的整个操作系统都依赖于一个 python 解释器。所以这个默认的,你不想卸载。如果这样做,您在查找桌面任务栏以及基本上所有内容时都会陷入混乱。
其他案例
在我将 ubuntu 升级到 20.04 后,这发生在我的 python3.7 安装上,但不是我的主要 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:deadsnakes/ppa 的 3.9)并且它不起作用
sudo apt install python3-distutils
然后它对我有用
sudo apt install python3.9-distutils
目前,我正在使用 ubuntu 18.04
和 python 3.6.9
。以 mentioned here 运行以下命令后,我的问题得到解决:
sudo apt-get install python3-dev
更多详细信息:需要 python 中的某些未安装的模块。
对我来说,问题是通过专门使用 python3 解决的,因此确保使用了 python3.8
python --version
Python 3.7.5
python3 --version
Python 3.8.5
尝试在 pipenv 中为 python 3.9 版安装 python3.9-distutils 后,我仍然收到错误消息。我注意到 here python3.9-distutils 与该软件包的早期版本冲突,无法在 Ubuntu18.04 上安装。
我继续使用带有 pipenv 的 python_version = "3.6"
,否则 $ pipenv install
将采用最高版本的 python 并将其写入 Pipfile
和 Pipfile.lock
。
$ pipenv --rm #To remove the old environment
$ rm Pipfile* #Remove both Pipfiles
$ pipenv install --python 3.6
不定期副业成功案例分享
sudo apt-get install python3-pip
和sudo apt-get install python3-setuptools