所以我有一个全新的 Debian 安装。我安装了pythons 3.5,3.6,3.7:
root@m2:~# apt-get install python3.{5,6,7}-dev
并尝试设置一些 virtualenvs:
for i in 5 6 7 ; do dir=venv3.$i; echo $dir; mkdir $dir; virtualenv $dir --python=python3.$i; done
结果:
-------------
venv3.5
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /root/venv3.5/bin/python3.5
Also creating executable in /root/venv3.5/bin/python
Installing setuptools, pip, wheel...done.
-------------
venv3.6
Running virtualenv with interpreter /usr/bin/python3.6
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 25, in <module>
import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'
-------------
venv3.7
Running virtualenv with interpreter /usr/bin/python3.7
Using base prefix '/usr'
/usr/local/lib/python2.7/dist-packages/virtualenv.py:1047: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /root/venv3.7/bin/python3.7
Also creating executable in /root/venv3.7/bin/python
Installing setuptools, pip, wheel...done.
知道如何解决 python 3.6 的这个问题吗?
确切的版本是:
root@m2:~# dpkg-query -s python3.6
Package: python3.6
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 326
Maintainer: Matthias Klose <[email protected]>
Architecture: amd64
Multi-Arch: allowed
Version: 3.6.8-1
同时,在一些旧系统上我也有 debian 8 和 python3.6,并且它工作正常:
root@m1:~# dpkg-query -s python3.6
Package: python3.6
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 315
Maintainer: Matthias Klose <[email protected]>
Architecture: amd64
Multi-Arch: allowed
Version: 3.6.6-4
root@m1:~# virtualenv venv3.6 --python=python3.6
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /root/venv3.6/bin/python3.6
Also creating executable in /root/venv3.6/bin/python
Installing setuptools, pip, wheel...
done.
答案1
我也遇到了同样的问题Debian 测试/破坏者:既然python3
是目标python3.7
,开始一个新的虚拟环境python3.6
由Debian-apt失败(当2.7
, 3.5
&3.7
成功时):
$ virtualenv --clear --python=python3.6 .venv
Running virtualenv with interpreter /usr/bin/python3.6
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 25, in <module>
import distutils.sysconfig
ModuleNotFoundError: No module named 'distutils.sysconfig'
zsh: exit 1 virtualenv --clear --python=python3.6 .venv
我环顾四周,看起来像Debian 的错。我无法修复它,然后我删除了Debian 3.6 风格我python3.6
从源代码安装用户域(下列的这篇文章的步骤)。
$ cd ~
$ mkdir pythonroot
$ mkdir opt
$ mkdir app
$ cd opt
$ wget Python-3.6.8.tgz
$ tar -xvzf Python-3.6.8.tgz
$ cd Python-3.6.8
$ ./configure --enable-optimizations --with-ensurepip=install --prefix="$HOME"/pythonroot
$ make
$ make install
$ cd ~/app
$ virtualenv --python ~/pythonroot/bin/python3.6 .venv
$ source .venv/bin/activate
(.venv)$ python -V
Python 3.6.8