Frage

I'm trying to use Pyinstaller to make an exe of my python code to easily distribute. Every time I try run pyinstaller.py I get an error "[Errno 22] invalid mode ('rb') or filename: ''"

I've seen a few other posts on this issue saying the problem is usually caused by hardcoding in filepaths for reading data, but all my filepaths are done using variables and asking the user where the files are located.

File "pyinstaller.py", line 18, in <module>
run()
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\main.py", line 88, in run
run_build(opts, spec_file, pyi_config)
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\main.py", line 46, in run_build
PyInstaller.build.main(pyi_config, spec_file, **opts.__dict__)
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 1924, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 1873, in build
execfile(spec)
File "\PyInstaller-2.1\PyInstaller-2.1\guimain\guimain.spec", line 17, in <module>
console=True )
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 1170, in __init__
strip_binaries=self.strip, upx_binaries=self.upx,
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 1008, in __init__
self.__postinit__()
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 309, in __postinit__
self.assemble()
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 1050, in assemble
dist_nm=inm)
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 842, in checkCache
digest = cacheDigest(fnm)
File "\PyInstaller-2.1\PyInstaller-2.1\PyInstaller\build.py", line 796, in cacheDigest
data = open(fnm, "rb").read()
IOError: [Errno 22] invalid mode ('rb') or filename: ''

anyone have any ideas how I can start to fix this?

edit: Using version 2.1 of pyinstaller

edit: So I tried testing my code by creating this:

import pandas as pd

if __name__ == '__main__':
    maindata = pd.DataFrame
    print maindata

which is giving me the same error.

War es hilfreich?

Lösung 2

Well reinstalled pywin32 and now working :S just going go with it

Andere Tipps

I had the same issues but found these other solutions did not fix the problem. I did however find a fix as follows:

First, my situation may be a little different to the OP as I'm using the Anaconda Python distribution on Windows 7, and used the conda command line too to install pywin32, and then used pip to install pyinstaller.

I found the same IOError was preceded by this earlier error message in the pyinstaller output log:

ImportError: No system module 'pywintypes' (pywintypes27.dll)  

The solution that fixed both errors was to copy the DLL files:

pywintypes27.dll
pythoncom27.dll 

sitting in: C:\<anaconda-dir>\Lib\site-packages\win32

to C:\<anaconda-dir>\Lib\site-packages\win32\lib

Where <anaconda-dir> will either be your root Anaconda directory:

C:\Users\<username>\AppData\Local\Continuum\Anaconda\ by default,

or an environment you have set up e.g.

C:\Users\<username>\AppData\Local\Continuum\Anaconda\envs\<environment-name>

A came across this answer thanks to Tompa here, who found it solved a similar problem in py2exe.

Just spent the better part of a week tracking this bug down. Was getting this error just by trying to compile a script importing numpy or pandas and printing "hello world".

Eventually fixed it by running command prompt as administrator... Yeah.

Hope this helps some poor desperate soul.

reinstall pywin32 and now working.

sourceforge.net/projects/pywin32/files/pywin32/

find the latest

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/

mine is win 64 so

get http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/pywin32-218.win-amd64-py2.7.exe/download

I know this is an old thread, but I just solved a very similar problem on my own and thought I'd post this in case it helps anyone else.

I was getting

OSError: [Errno 22] Invalid agument

without any other specificity to help me debug.

In my code there was a filename where the code was going to save something to a mapped network drive "S". On my local machine, I don't actually have a "S" drive. For testing purposes I used an exception to catch and redirect. Anyway, it seems pyinstaller was choking on the fact that the code refers to the "S" drive that doesn't exist. Not sure if it thought it needed to import a module or just was annoyed it couldn't find "S". Anyway this fix solved it:

#ORIG CODE THAT FAILED
#filename = 'S:\\MyFile\\Saves\\HELLO_WORLD.TXT'
first = 'S:'
rest = '\\MyFile\\Saves\\HELLO_WORLD.TXT''
filename = first + rest

Frustrating that at some point previously I had been able to freeze this code using pyinstaller, but something changed. Hope that helps someone out there!

Try to change your file name I solved this problem maybe by doing that

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top