ImportError:没有名为zlib的模块; TOX

时间:2016-06-20 17:31:50

标签: python unit-testing python-2.6 python-unittest tox

我正在尝试以python 2.6运行tox测试。我刚刚安装了2.6,现在我已经超过了“解释器错误:没有python 2.6”样式错误,但是tox现在正在zlib崩溃。但是Zlib在我的机器上。我的tox问题看起来像:

$ tox -e py26
GLOB sdist-make: /home/cchilders/work_projects/webapi/setup.py
py26 create: /home/cchilders/work_projects/webapi/.tox/py26
ERROR: invocation failed (exit code 1), logfile: /home/cchilders/work_projects/webapi/.tox/py26/log/py26-0.log
ERROR: actionid: py26
msg: getenv
cmdargs: ['/home/cchilders/.virtualenvs/webapi/bin/python', '-m', 'virtualenv', '--python', '/usr/local/bin/python2.6', 'py26']
env: {'MANDATORY_PATH': '/usr/share/gconf/ubuntu.mandatory.path', 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/cchilders', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'PROJECT_HOME': '/home/cchilders/work_projects', 'UPSTART_EVENTS': 'xsession started', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'XDG_SESSION_TYPE': 'x11', 'QT_IM_MODULE': 'ibus', 'LOGNAME': 'cchilders', 'USER': 'cchilders', 'PATH': '/home/cchilders/work_projects/webapi/.tox/py26/bin:/home/cchilders/.virtualenvs/webapi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/bin/virtualenvwrapper.sh', 'XDG_VTNR': '7', 'GNOME_KEYRING_CONTROL': '', 'VIRTUALENVWRAPPER_SCRIPT': '/usr/local/bin/virtualenvwrapper.sh', 'DISPLAY': ':0', 'VIRTUALENVWRAPPER_PROJECT_FILENAME': '.project', 'XDG_SESSION_DESKTOP': 'ubuntu', 'TERM': 'xterm', 'SHELL': '/bin/bash', 'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0', 'XAUTHORITY': '/home/cchilders/.Xauthority', 'LANGUAGE': 'en_US', 'DEFAULTS_PATH': '/usr/share/gconf/ubuntu.default.path', 'SHLVL': '1', 'QT_QPA_PLATFORMTHEME': 'appmenu-qt5', 'POSTMARK_KEY': 'ba7663a2-19ba-4a42-bf69-5b4485fcab6f', 'TDSDUMP': '/tmp/freetds.log', 'UPSTART_INSTANCE': '', 'COMPIZ_CONFIG_PROFILE': 'ubuntu', 'WINDOWID': '69206027', 'EDITOR': 'nano', 'CLUTTER_IM_MODULE': 'xim', 'IM_CONFIG_PHASE': '1', 'PYTHONHASHSEED': '209016217', 'GPG_AGENT_INFO': '/run/user/1000/keyring/gpg:0:1', 'HOME': '/home/cchilders', 'QT4_IM_MODULE': 'xim', 'LANG': 'en_US.UTF-8', 'SSH_AUTH_SOCK': '/run/user/1000/keyring/ssh', 'XDG_RUNTIME_DIR': '/run/user/1000', 'WORKON_HOME': '/home/cchilders/.virtualenvs', 'GTK_IM_MODULE': 'ibus', 'PYTHONPATH': '/home/cchilders/work_projects', 'COMP_WORDBREAKS': ' \t\n"\'><;|&(:', 'SESSIONTYPE': 'gnome-session', 'VIRTUAL_ENV': '/home/cchilders/work_projects/webapi/.tox/py26', 'VTE_VERSION': '3803', 'GDMSESSION': 'ubuntu', 'XMODIFIERS': '@im=ibus', 'UPSTART_JOB': 'unity7', 'VIRTUALENVWRAPPER_WORKON_CD': '1', 'PS1': '\n\\[\\033[0;35m\\](webapi)\\[\\e[0m\\] \\[\\033[0;32m\\]\\u\\[\\e[0m\\]:\\[\\033[1;33m\\]\\w\\[\\e[0m\\]\\[\\e[0;36m\\] (master)\\[\\e[0m\\] \n$ ', 'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/', 'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0', 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg', 'XDG_CURRENT_DESKTOP': 'Unity', 'XDG_SESSION_ID': 'c1', 'DBUS_SESSION_BUS_ADDRESS': 'unix:abstract=/tmp/dbus-bmBbueNSW6', '_': '/home/cchilders/.virtualenvs/webapi/bin/tox', 'GNOME_KEYRING_PID': '', 'SESSION': 'ubuntu', 'DESKTOP_SESSION': 'ubuntu', 'UPSTART_SESSION': 'unix:abstract=/com/ubuntu/upstart-session/1000/1300', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'VIRTUALENVWRAPPER_HOOK_DIR': '/home/cchilders/.virtualenvs', 'OLDPWD': '/home/cchilders', 'GDM_LANG': 'en_US', 'GTK_MODULES': 'overlay-scrollbar:unity-gtk-module', 'INSTANCE': '', 'PWD': '/home/cchilders/work_projects/webapi', 'JOB': 'unity-settings-daemon', 'BASH_PROF': '/home/cchilders/.bash_profile', 'LS_COLORS': 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:', 'COMPIZ_BIN_PATH': '/usr/bin/', 'XDG_SEAT': 'seat0'}

Traceback (most recent call last):
  File "/home/cchilders/.virtualenvs/webapi/lib/python2.7/site-packages/virtualenv.py", line 22, in <module>
    import zlib
ImportError: No module named zlib
Running virtualenv with interpreter /usr/local/bin/python2.6

ERROR: InvocationError: /home/cchilders/.virtualenvs/webapi/bin/python -m virtualenv --python /usr/local/bin/python2.6 py26 (see /home/cchilders/work_projects/webapi/.tox/py26/log/py26-0.log)
_____________________________________________________________________________________ summary _____________________________________________________________________________________
ERROR:   py26: InvocationError: /home/cchilders/.virtualenvs/webapi/bin/python -m virtualenv --python /usr/local/bin/python2.6 py26 (see /home/cchilders/work_projects/webapi/.tox/py26/log/py26-0.log)

我尝试升级这些:

(webapi) cchilders:~/Downloads/Python-2.6.9 
$ sudo apt-get install --upgrade zlibc zlib1g zlib1g-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
zlib1g is already the newest version.
zlib1g-dev is already the newest version.
zlibc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.

Python 2.6正在运行,但是当我安装它时,我收到了警告:

Failed to find the necessary bits to build these modules:
_bsddb             _curses            _curses_panel   
_hashlib           _sqlite3           _ssl            
_tkinter           bsddb185           bz2             
dbm                dl                 gdbm            
imageop            linuxaudiodev      ossaudiodev     
readline           sunaudiodev        zlib            
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
crypt              nis                                

running build_scripts

检查setup.py导致看到python想要zlib 1.3.3,但我只是尝试升级所以它应该是最新的。

将测试作为3.4工作:

$ tox -e py34   py34:命令成功   恭喜:)

这里有什么问题?有没有办法重新安装不会在zlib上出错的python2.6?谢谢

2 个答案:

答案 0 :(得分:1)

由晦涩的ubuntu问题解决:

http://joequery.me/guides/python26-no-module-zlib/

答案 1 :(得分:0)

  

检查setup.py导致看到python想要zlib 1.3.3,但我只是尝试升级所以它应该是最新的。

这已经很晚了,但如果其他人有类似的问题:

tox似乎只创建了一次virtualenv。如果它这样做了,你之后修改了requirements.txt文件,您需要re-create it

  

强制tox重新创建(特定)虚拟环境:

tox --recreate -e py27 
     

会触发完全重新安装   现有的py27环境(如果不存在,则重新创建)。