virtualenv -p python2.6 fails with ValueError: zero length field name in format

Bug #1398059 reported by Marius Gedminas
26
This bug affects 5 people
Affects Status Importance Assigned to Milestone
python-virtualenv (Debian)
Fix Released
Unknown
python-virtualenv (Ubuntu)
Fix Released
Low
Unassigned
Trusty
Triaged
Low
Unassigned
Wily
Triaged
Low
Unassigned

Bug Description

I'm trying to create a virtualenv with Python 2.6, using python2.6 2.6.9-3.2+utopic1 from ppa:fkrull/deadsnakes. This fails:

    $ virtualenv -p python2.6 /tmp/py26
    Running virtualenv with interpreter /usr/bin/python2.6
    New python executable in /tmp/py26/bin/python2.6
    Also creating executable in /tmp/py26/bin/python
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/virtualenv.py", line 2378, in <module>
        main()
      File "/usr/lib/python3/dist-packages/virtualenv.py", line 830, in main
        symlink=options.symlink)
      File "/usr/lib/python3/dist-packages/virtualenv.py", line 1016, in create_environment
        '/usr/share/python-wheels/{}-*.whl'.format(project))
    ValueError: zero length field name in format

ProblemType: Bug
DistroRelease: Ubuntu 14.10
Package: python-virtualenv 1.11.6-2
ProcVersionSignature: Ubuntu 3.16.0-26.34-generic 3.16.7-ckt1
Uname: Linux 3.16.0-26-generic x86_64
ApportVersion: 2.14.7-0ubuntu8
Architecture: amd64
CurrentDesktop: GNOME
Date: Mon Dec 1 18:00:21 2014
EcryptfsInUse: Yes
InstallationDate: Installed on 2012-07-25 (859 days ago)
InstallationMedia: Ubuntu 12.04 LTS "Precise Pangolin" - Release amd64 (20120425)
PackageArchitecture: all
SourcePackage: python-virtualenv
UpgradeStatus: Upgraded to utopic on 2014-10-24 (38 days ago)

Revision history for this message
Marius Gedminas (mgedmin) wrote :
Revision history for this message
Marius Gedminas (mgedmin) wrote :

Note that upstream version 1.11.6 (installed via pip install --user virtualenv) works fine with all pythons from 2.6 to 3.4, as well as with pypy.

Revision history for this message
Barry Warsaw (barry) wrote :

This is because in Python 2.6, an index was required inside the .format() field's brace placeholder:

% python2.6 -c "'{}'.format('foo')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: zero length field name in format

Python 2.7 relaxed that constraint so that its .format() syntax is compatible with Python 3.

Our virtualenv hack to use unvendored wheels requires the relaxed syntax.

What doesn't make sense though is why Python 2.6 is trying to execute code out of /usr/lib/python3/dist-packages/virtualenv.py. IIRC, virtualenv supports alternative Python's by re-execing itself using the other Python. This is borderline crazy and has caused other problems in the past. I also believe that upstream virtualenv was recently (or will recently be) rewritten to avoid this error-prone re-exec.

The fix of course would be simple, but it's questionable whether it's worth the effort given that Python 2.6 isn't supported on Ubuntu since Lucid, and we'd probably have to make the change first in Debian, which doesn't support Python 2.6 in Wheezy. Then there are the issues of SRU'ing those changes into the relevant Ubuntu releases.

Maybe a more tractable solution is to add a tweaked virtualenv to the PPA? Since you're getting Python 2.6 out of there, it wouldn't be much additional effort to put a compatible virtualenv in there too.

Changed in python-virtualenv (Ubuntu):
status: New → Opinion
importance: Undecided → Low
Revision history for this message
Scott Moser (smoser) wrote :

fwiw, i can verify that:
$ diff -u /usr/lib/python3/dist-packages/virtualenv.py.dist /usr/lib/python3/dist-packages/virtualenv.py
--- /usr/lib/python3/dist-packages/virtualenv.py.dist 2015-07-17 11:34:27.019820883 -0400
+++ /usr/lib/python3/dist-packages/virtualenv.py 2015-07-17 11:34:29.887856748 -0400
@@ -1013,7 +1013,7 @@
             raise
     for project in DEBIAN_WHEEL_DEPS:
         wheel_names = glob.glob(
- '/usr/share/python-wheels/{}-*.whl'.format(project))
+ '/usr/share/python-wheels/{0}-*.whl'.format(project))
         if len(wheel_names) == 0:
             raise RuntimeError('missing dependency wheel %s' % project)
         assert len(wheel_names) == 1, wheel_names

that makes virtualenv seemingly functional for me.
found that at
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=754248

Revision history for this message
Barry Warsaw (barry) wrote :

This is a low impact change, so if it makes folks lives easier, I'm happy to apply it. No ETA on that atm, but +1 for making this change to wily and trusty.

Changed in python-virtualenv (Ubuntu):
status: Opinion → Triaged
Changed in python-virtualenv (Ubuntu Trusty):
importance: Undecided → Low
status: New → Triaged
Changed in python-virtualenv (Debian):
status: Unknown → New
Changed in python-virtualenv (Debian):
status: New → Fix Released
Revision history for this message
Kai Kasurinen (kai-kasurinen) wrote :

 python-virtualenv (15.0.3+ds-3) unstable; urgency=medium
 .
   * d/patches/use-wheels.patch: Use a Python 2.6-friendly format string.
     (Closes: #754248)

Changed in python-virtualenv (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.