Python“;IOError:[Errno 22]参数无效“;使用cPickle将大型阵列写入网络驱动器时

Python“;IOError:[Errno 22]参数无效“;使用cPickle将大型阵列写入网络驱动器时,python,ioerror,nas,pickle,Python,Ioerror,Nas,Pickle,编辑: 根据J.F.Sebastian的建议,我可以更简单地得到相同的错误: Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introd

编辑: 根据J.F.Sebastian的建议,我可以更简单地得到相同的错误:

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.

In [1]: open(r'c:\test.bin', 'wb').write('a'*67076095)

In [2]: open(r'c:\test.bin', 'wb').write('a'*67076096)

In [3]: open(r'z:\test.bin', 'wb').write('a'*67076095)

In [4]: open(r'z:\test.bin', 'wb').write('a'*67076096)
---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)

C:\Documents and Settings\User\<ipython console> in <module>()

IOError: [Errno 22] Invalid argument

In [5]:
以下是我在ipython提示符下生成崩溃的步骤:

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.

In [1]: pwd
Out[1]: 'C:\\Documents and Settings\\User'

In [2]: run test
Writing 67080056 bytes...
Successfully written.
Writing 67080064 bytes...
Successfully written.

In [3]: cd Z:
Z:\

In [4]: pwd
Out[4]: 'Z:\\'

In [5]: run 'C:\\Documents and Settings\\User\\test'
Writing 67080056 bytes...
Successfully written.
Writing 67080064 bytes...
---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)

C:\Documents and Settings\User\test.py in <module>()
      8 b = numpy.zeros(8385008)
      9 print "Writing %i bytes..."%(b.nbytes)
---> 10 cPickle.dump(b, open('test_b.pkl', 'wb'), protocol=2)
     11 print "Successfully written."
     12

IOError: [Errno 22] Invalid argument
WARNING: Failure executing file: <C:\\Documents and Settings\\User\\test.py>

In [6]:
Python 2.6.4(r264:75708,2009年10月26日,08:23:19)[MSC v.1500 32位(英特尔)]
有关详细信息,请键入“版权”、“信用”或“许可证”。
IPython 0.10——一种增强的交互式Python。
?         -> 介绍和概述IPython的功能。
%快速参考->快速参考。
帮助->Python自己的帮助系统。
对象?->有关“对象”的详细信息?对象也可以工作??打印更多。
欢迎使用pylab,这是一个基于matplotlib的Python环境。
有关详细信息,请键入“帮助(pylab)”。
In[1]:pwd
输出[1]:'C:\\Documents and Settings\\User'
在[2]中:运行测试
正在写入67080056字节。。。
写得好。
正在写入67080064字节。。。
写得好。
在[3]:cd Z中:
Z:\
[4]:pwd
Out[4]:'Z:\\'
在[5]中:运行“C:\\Documents and Settings\\User\\test”
正在写入67080056字节。。。
写得好。
正在写入67080064字节。。。
---------------------------------------------------------------------------
IOError回溯(最近一次呼叫最后一次)
C:\Documents and Settings\User\test.py in()
8 b=整数零(8385008)
9打印“写入%i字节…”%(b.n字节)
--->10 cPickle.dump(b,open('test_b.pkl','wb'),协议=2)
11打印“已成功写入”
12
IOError:[Errno 22]参数无效
警告:执行文件失败:
在[6]中:

是机器上的本地硬盘。Z:是我们的网络连接存储。

我认为问题与以下方面有关:

…所以,试试看: 打开(r'z:\test.bin',w+b')。写入('a'*67080064)


*注意参数:“w+b”

注意:
numpy
数组可以自己pickle:
a.dump
是否打开(r'z:\test.bin',wb')。写入('a'*67080064)
工作?问得好!复制相同错误的更简单方法。我会编辑这个问题。这个bug是在Visual C++ 2008中固定的,所以问题不存在于Python 2.7 + OPEN(R'Z:\Test.bin,WB)。写(‘a’* 67076096)失败,打开(R'Z:\Test.bin,WB)。写(‘a’*67076095’)不会失败,但太小了。幸运的是,open(r'z:\test.bin,'w+b')。write('a'*67076096)可以工作!不适用于Mac OS X。修复此问题的修补程序正在审查很长一段时间
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

  Welcome to pylab, a matplotlib-based Python environment.
  For more information, type 'help(pylab)'.

In [1]: pwd
Out[1]: 'C:\\Documents and Settings\\User'

In [2]: run test
Writing 67080056 bytes...
Successfully written.
Writing 67080064 bytes...
Successfully written.

In [3]: cd Z:
Z:\

In [4]: pwd
Out[4]: 'Z:\\'

In [5]: run 'C:\\Documents and Settings\\User\\test'
Writing 67080056 bytes...
Successfully written.
Writing 67080064 bytes...
---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)

C:\Documents and Settings\User\test.py in <module>()
      8 b = numpy.zeros(8385008)
      9 print "Writing %i bytes..."%(b.nbytes)
---> 10 cPickle.dump(b, open('test_b.pkl', 'wb'), protocol=2)
     11 print "Successfully written."
     12

IOError: [Errno 22] Invalid argument
WARNING: Failure executing file: <C:\\Documents and Settings\\User\\test.py>

In [6]: