4

so i have a fresh debian install. I installed pythons 3.5,3.6,3.7:

root@m2:~# apt-get install python3.{5,6,7}-dev

and try to set up some virtualenvs:

for i in 5 6 7 ; do dir=venv3.$i; echo $dir; mkdir $dir; virtualenv $dir --python=python3.$i; done

result:

-------------
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.

any idea how to fix this for python 3.6?

the exact version is:

root@m2:~# dpkg-query -s python3.6
Package: python3.6
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 326
Maintainer: Matthias Klose <doko@debian.org>
Architecture: amd64
Multi-Arch: allowed
Version: 3.6.8-1

Meanwhile, on some older system I also have debian 8 and python3.6, and there it works ok:

root@m1:~# dpkg-query -s python3.6
Package: python3.6
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 315
Maintainer: Matthias Klose <doko@debian.org>
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.
  • Any specific reason you are creating three virtual env's at once? – Raju Devidas Jan 9 at 19:33
  • Well I just need the one with py36. But I wasnt able to do it, I wanted to check what's wrong. Now I presume, that this is some problem with python3.6 from debian repo – murison Jan 9 at 20:12
  • Well, the issue is present in upstream, I was having similar issues creating a virtualenv. The upstream codebase for virtualenv is having bugs which might have got carried in Debian repos. Take a look at github.com/pypa/pipenv/issues/2871 – Raju Devidas Jan 10 at 11:41
  • I filed a bug under debian: bugs.debian.org/cgi-bin/bugreport.cgi?bug=918881 – murison Jan 10 at 16:48
  • 1
    A work-around may be to find out where the distutils package is supposed to be for Python 3.6, e.g. by running python3.6 -c 'import distutils; print(distutils.__file__)' and replace its contents with the files used by Python 3.7 (which appears to be working in your case). – Peter Bašista Jan 31 at 10:51
0

I had the same problem on Debian testing/buster : since python3 is targeting python3.7, starting a new virtual environment with python3.6 provided by Debian-apt fails (when 2.7, 3.5 & 3.7 succeeded) :

$ 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

I look around and it looks like Debian's fault. I am not able to fix it, then I removed Debian's 3.6 flavor and I installed python3.6 from source in user-land (following this post's step).

$ 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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.