我似乎无法正确安装zlib,我在Ubuntu10.4上从源代码安装了Python
'######## edit #####################
bobince和Luper帮忙.
确保安装这些软件包,然后重新编译Python:
sudo aptitude install zlib1g-dev libreadline6-dev libdb4.8-dev libncurses5-dev
'##################### ############
安装后,我尝试安装setuptools.py
$ sh setuptools-0.6c11-py2.7.egg
Traceback (most recent call last):
File "<string>", line 1, in <module>
zipimport.ZipImportError: can't decompress data; zlib not available
Run Code Online (Sandbox Code Playgroud)
然后我安装了zlib:
$ sudo aptitude install zlibc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
zlibc
0 packages upgraded, 1 newly installed, 0 to remove and …Run Code Online (Sandbox Code Playgroud) 在可能的DEFLATE压缩级别[0 .. 9]中,哪一个Deflater.DEFAULT_COMPRESSION与Java完全对应?在Java源代码中,我将其视为public static final int DEFAULT_COMPRESSION = -1;
我正在尝试在Python2.6下创建Python 2.7虚拟环境,我只是运行:
virtualenv --python=python27 #python27 correctly leads to my python installation in /opt/python2.7/bin/python
Run Code Online (Sandbox Code Playgroud)
Virtualenv失败并出现以下错误
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 17, in <module>
import zlib
ImportError: No module named zlib
Run Code Online (Sandbox Code Playgroud)
这让我很困惑,因为:
1)我显然有python zlib模块.当我在python 2.6的交互式环境中运行"import zlib"时,我可以轻松导入它.
2)我的系统中安装了zlib(centos):
[me@mycomp]# rpm -qa | grep zlib
zlib-1.2.3-29.el6.x86_64
zlib-1.2.3-29.el6.i686
zlib-devel-1.2.3-29.el6.x86_64
Run Code Online (Sandbox Code Playgroud)
关于这个问题还有另外两个问题,在这里和这里,在这两种情况下,人们根本没有安装zlib,这不是我的情况(我在python 2.6中有它,这应该没问题?),他们也使用pythonbrew这显然不再处于积极发展阶段.
为什么virtualenv找不到zlib?virtualenv如何查找其模块?我需要在Python2.7中安装zlib吗?或者重新安装Python2.7以便支持zlib?
旁注:请不要问我为什么使用旧版本,这不是我的选择.
我有一个压缩输出文件的脚本.问题是其中一个文件超过4Gigs.如何将我的脚本转换为使用ZIP64扩展而不是标准zip?
这是我目前如何拉链:
try:
import zlib
compression = zipfile.ZIP_DEFLATED
except:
compression = zipfile.ZIP_STORED
modes = { zipfile.ZIP_DEFLATED: 'deflated',
zipfile.ZIP_STORED: 'stored',
}
compressed_name = 'edw_files_' + datetime.strftime(date(), '%Y%m%d') + '.zip'
print 'creating archive'
zf = zipfile.ZipFile('edw_files_' + datetime.strftime(date(), '%Y%m%d') + '.zip', mode='w')
try:
zf.write(name1, compress_type=compression)
zf.write(name2, compress_type=compression)
zf.write(name3, compress_type=compression)
finally:
print 'closing'
zf.close()
Run Code Online (Sandbox Code Playgroud)
谢谢!法案
我目前有一个链接到两个第三方库的项目.这些库必须由它们自己构建,然后链接到项目.一个是taglib,另一个是zlib.我注意到当你在taglib目录中使用Cmake-gui程序时,你需要指定zlib的构建和安装位置.
我的目标是让CMake为我的程序做类似的事情.由于这些库存储的位置不一致,我如何提示用户提供所需库的路径?
我希望这足够具体.
我想尝试使用java.util.zip中的Deflate和Inflate类进行zlib压缩.
我能够使用Deflate压缩代码,但在解压缩时,我遇到了这个错误 -
Exception in thread "main" java.util.zip.DataFormatException: unknown compression method
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:238)
at java.util.zip.Inflater.inflate(Inflater.java:256)
at zlibCompression.main(zlibCompression.java:53)
Run Code Online (Sandbox Code Playgroud)
这是我目前的代码 -
import java.util.zip.*;
import java.io.*;
public class zlibCompression {
/**
* @param args
*/
public static void main(String[] args) throws IOException, DataFormatException {
// TODO Auto-generated method stub
String fname = "book1";
FileReader infile = new FileReader(fname);
BufferedReader in = new BufferedReader(infile);
FileOutputStream out = new FileOutputStream("book1out.dfl");
//BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename));
Deflater compress = new Deflater();
Inflater …Run Code Online (Sandbox Code Playgroud) 在zlib 1.2.7,文件inffast.c,第320行,有一个我不明白的声明:
strm->avail_out = (unsigned)(out < end ?
257 + (end - out) : 257 - (out - end));
Run Code Online (Sandbox Code Playgroud)
变量end和out是两个指针到输出缓冲区.这种说法作出了努力来计算end - out的时候end > out和out - end当out >= end,但我不明白为什么会想这样做.在我看来,最终的结果是相同的,也就是说,这条线也可能已被写入:
strm->avail_out = 257 + (end - out);
Run Code Online (Sandbox Code Playgroud)
两个指针的区别有一个带符号的整数类型ptrdiff_t(C99 6.5.6:9),并且257有类型int.增加发生在这两者之间的更高等级的类型,我不知道三元运营商可能正在防范什么.
我正在尝试将我的python命令行应用程序转换为使用py2app的应用程序.每次我尝试导入zlib或尝试安装setuptools时,都会收到错误:没有名为zlib的模块.
Python是用brew安装的.我搜索了互联网的每个角落和堆栈溢出,我已经重新安装了使用brew的python,我已经安装了所有与Xcode CLI相关的东西:
xcode-select --install
Run Code Online (Sandbox Code Playgroud)
我也跑了:
ls /usr/include/zlib.h
Run Code Online (Sandbox Code Playgroud)
我可以看到zlib应该在那里.
重新安装:
brew reinstall python
Run Code Online (Sandbox Code Playgroud)
不幸的是,这对我不起作用.我不知道有什么不对.
有任何想法吗?
zlib ×10
python ×4
c++ ×3
compression ×2
deflate ×2
java ×2
c ×1
cmake ×1
gzip ×1
homebrew ×1
inflate ×1
integration ×1
macos ×1
qt ×1
setuptools ×1
taglib ×1
virtualenv ×1
zip ×1
zipfile ×1