AndyC1000
asked on
How to run Python script on Windows machines
Dear all,
I have a python script that I need to circulate to users. I'm looking for advice - the easiest solution to run Python scripts on windows machines. The script uses Netcdf4.
I'll need to provide a list of instructions to non IT people so I'm hoping there's a straightforward solution.
Thanks
I have a python script that I need to circulate to users. I'm looking for advice - the easiest solution to run Python scripts on windows machines. The script uses Netcdf4.
I'll need to provide a list of instructions to non IT people so I'm hoping there's a straightforward solution.
Thanks
You need to install Python and put it in the path. https://www.python.org/downloads/ And you will have to get Netcdf4 from here because it is not built into Python: https://github.com/Unidata/netcdf4-python You might want to look at py2exe http://www.py2exe.org/ to see if you can just distribute an EXE.
Here is a tutorial on creating a exe using py2exe
http://www.logix4u.net/component/content/article/27-tutorials/44-how-to-create-windows-executable-exe-from-python-script
http://www.logix4u.net/component/content/article/27-tutorials/44-how-to-create-windows-executable-exe-from-python-script
If your script is python2 rather than python3, I find pyinstaller (https://github.com/pyinstaller/pyinstaller/wiki) much friendlier than py2exe. Assuming you have pywin32 installed (which you'll need for either py2exe or pyinstaller) and pip installed then...
will install pyinstaller. Once pyinstaller is installed:
Will create a one file bundled free-standing executable of your python script. It'll be called yourscript.exe and be in a dist subdirectory that it will have created.
Pyinstaller's support for python 3 is still experimental. If you're using python3, py2exe is probably the better bet. But if you're not, I suggest giving pyinstaller a try.
pip install pyinstaller
will install pyinstaller. Once pyinstaller is installed:
pyinstaller -F yourscript.py
Will create a one file bundled free-standing executable of your python script. It'll be called yourscript.exe and be in a dist subdirectory that it will have created.
Pyinstaller's support for python 3 is still experimental. If you're using python3, py2exe is probably the better bet. But if you're not, I suggest giving pyinstaller a try.
ASKER
I started using py2exe when the first post came through. I'm getting the following error when I try to run the executable.
python import error: No module named netCDF4_utils
In the python code I added netCDF4_utils to the import statement to try to solve the above error. No change.
from netCDF4 import Dataset, num2date, netCDF4_utils
Note I ran the following from the console during development pip install C:\Anaconda\ModulesDownloa ded\netCDF 4-1.1.3-cp 27-none-wi n_amd64.wh l with no errors
I feel that I'm close to a solution. I will start to look at pyinstaller as this needs to be finalised soon.
python import error: No module named netCDF4_utils
In the python code I added netCDF4_utils to the import statement to try to solve the above error. No change.
from netCDF4 import Dataset, num2date, netCDF4_utils
Note I ran the following from the console during development pip install C:\Anaconda\ModulesDownloa
I feel that I'm close to a solution. I will start to look at pyinstaller as this needs to be finalised soon.
Are you running this in Cygwin?
ASKER
I'm using Spyder as my IDE and I'm running the executable from the command line.
I don't have pyWin32 installed I'll look into it now.
I don't have pyWin32 installed I'll look into it now.
Once you have developed the python code in Spyder and are ready to create the exe just run the py2exe command in the windows command prompt to create the exe eg
python setup.py py2exe
python setup.py py2exe
ASKER
I'm using python 2.7.
ASKER
I thought python setup.py py2exe ran successfully.
Just noticed the following errors:
The following modules appear to be missing
['Carbon', 'Carbon.Files', 'IronPython.Runtime.Except ions', 'IronPythonConsole',
'Numeric', 'Pyrex.Compiler.Main', 'System', 'System.Windows.Forms.Clip board', '
__config__', '__svn_version__', '_curses', '_scproxy', '_sysconfigdata', 'builti
ns', 'clr', 'code_generators.genapi', 'code_generators.numpy_api ', 'compat.long'
, 'configparser', 'console', 'copyreg', 'core.abs', 'core.max', 'core.min', 'cor
e.round', 'dummy.Process', 'fcompiler.FCompiler', 'genapi', 'modes.editingmodes'
, 'numarray', 'numpy.amax', 'numpy.amin', 'numpy.array', 'numpy.bool_', 'numpy.c
ompat.asbytes', 'numpy.compat.asbytes_nest ed', 'numpy.compat.asstr', 'numpy.comp
at.basestring', 'numpy.compat.bytes', 'numpy.compat.integer_type s', 'numpy.compa
t.isfileobj', 'numpy.compat.long', 'numpy.compat.open_latin1' , 'numpy.compat.uni
code', 'numpy.core.Inf', 'numpy.core.absolute', 'numpy.core.add', 'numpy.core.al
l', 'numpy.core.amax', 'numpy.core.amin', 'numpy.core.any', 'numpy.core.arange',
'numpy.core.around', 'numpy.core.array', 'numpy.core.array_repr', 'numpy.core.a
sarray', 'numpy.core.atleast_1d', 'numpy.core.atleast_2d', 'numpy.core.atleast_3
d', 'numpy.core.bitwise_and', 'numpy.core.bitwise_or', 'numpy.core.bitwise_xor',
'numpy.core.broadcast', 'numpy.core.cdouble', 'numpy.core.complexfloatin g', 'nu
mpy.core.concatenate', 'numpy.core.conjugate', 'numpy.core.csingle', 'numpy.core
.divide', 'numpy.core.dot', 'numpy.core.double', 'numpy.core.empty', 'numpy.core
.empty_like', 'numpy.core.equal', 'numpy.core.errstate', 'numpy.core.fastCopyAnd
Transpose', 'numpy.core.finfo', 'numpy.core.float32', 'numpy.core.float64', 'num
py.core.float_', 'numpy.core.geterrobj', 'numpy.core.greater', 'numpy.core.great
er_equal', 'numpy.core.hstack', 'numpy.core.iinfo', 'numpy.core.inexact', 'numpy
.core.inf', 'numpy.core.intc', 'numpy.core.integer', 'numpy.core.invert', 'numpy
.core.isfinite', 'numpy.core.isinf', 'numpy.core.isnan', 'numpy.core.isscalar',
'numpy.core.left_shift', 'numpy.core.less', 'numpy.core.less_equal', 'numpy.core
.linspace', 'numpy.core.longdouble', 'numpy.core.maximum', 'numpy.core.multiply'
, 'numpy.core.ndarray', 'numpy.core.newaxis', 'numpy.core.not_equal', 'numpy.cor
e.number', 'numpy.core.power', 'numpy.core.product', 'numpy.core.ravel', 'numpy.
core.remainder', 'numpy.core.reshape', 'numpy.core.result_type', 'numpy.core.rig
ht_shift', 'numpy.core.rollaxis', 'numpy.core.shape', 'numpy.core.signbit', 'num
py.core.sin', 'numpy.core.single', 'numpy.core.size', 'numpy.core.sqrt', 'numpy.
core.subtract', 'numpy.core.sum', 'numpy.core.swapaxes', 'numpy.core.take', 'num
py.core.transpose', 'numpy.core.ufunc', 'numpy.core.vstack', 'numpy.core.zeros',
'numpy.deprecate', 'numpy.dtype', 'numpy.expand_dims', 'numpy.eye', 'numpy.fft.
fft', 'numpy.fft.ifft', 'numpy.histogramdd', 'numpy.integer', 'numpy.intp', 'num
py.iscomplexobj', 'numpy.lib.add_newdoc', 'numpy.lib.asfarray', 'numpy.lib.i0',
'numpy.lib.imag', 'numpy.lib.iscomplexobj', 'numpy.lib.real', 'numpy.lib.triu',
'numpy.linalg.eigvals', 'numpy.linalg.inv', 'numpy.linalg.lstsq', 'numpy.ma.MAEr
ror', 'numpy.ma.MaskedArray', 'numpy.ma.filled', 'numpy.ma.getdata', 'numpy.ma.g
etmaskarray', 'numpy.ma.make_mask_descr' , 'numpy.ma.masked', 'numpy.ma.masked_ar
ray', 'numpy.ma.nomask', 'numpy.ndarray', 'numpy.random.rand', 'numpy.random.ran
dn', 'numpy.recarray', 'numpy_api', 'numpy_distutils', 'numpy_distutils.command.
build_flib', 'numpy_distutils.command.c puinfo', 'numpy_distutils.cpuinfo', 'nump
y_distutils.fcompiler', 'pkg_resources', 'pyreadline.keysyms.make_K eyPress', 'py
readline.keysyms.make_KeyP ress_from_ keydescr', 'pyreadline.keysyms.make_k eyinfo'
, 'pyreadline.keysyms.make_k eysym', 'setuptools', 'setuptools.command', 'setupto
ols.command.bdist_rpm', 'setuptools.command.develo p', 'setuptools.command.egg_in
fo', 'setuptools.command.instal l', 'setuptools.command.sdist' , 'sitecustomize',
'startup', 'testing.Tester', 'unittest2.case', 'urllib.error', 'urllib.parse', '
urllib.request', 'usercustomize', 'winreg']
Just noticed the following errors:
The following modules appear to be missing
['Carbon', 'Carbon.Files', 'IronPython.Runtime.Except
'Numeric', 'Pyrex.Compiler.Main', 'System', 'System.Windows.Forms.Clip
__config__', '__svn_version__', '_curses', '_scproxy', '_sysconfigdata', 'builti
ns', 'clr', 'code_generators.genapi', 'code_generators.numpy_api
, 'configparser', 'console', 'copyreg', 'core.abs', 'core.max', 'core.min', 'cor
e.round', 'dummy.Process', 'fcompiler.FCompiler', 'genapi', 'modes.editingmodes'
, 'numarray', 'numpy.amax', 'numpy.amin', 'numpy.array', 'numpy.bool_', 'numpy.c
ompat.asbytes', 'numpy.compat.asbytes_nest
at.basestring', 'numpy.compat.bytes', 'numpy.compat.integer_type
t.isfileobj', 'numpy.compat.long', 'numpy.compat.open_latin1'
code', 'numpy.core.Inf', 'numpy.core.absolute', 'numpy.core.add', 'numpy.core.al
l', 'numpy.core.amax', 'numpy.core.amin', 'numpy.core.any', 'numpy.core.arange',
'numpy.core.around', 'numpy.core.array', 'numpy.core.array_repr', 'numpy.core.a
sarray', 'numpy.core.atleast_1d', 'numpy.core.atleast_2d', 'numpy.core.atleast_3
d', 'numpy.core.bitwise_and', 'numpy.core.bitwise_or', 'numpy.core.bitwise_xor',
'numpy.core.broadcast', 'numpy.core.cdouble', 'numpy.core.complexfloatin
mpy.core.concatenate', 'numpy.core.conjugate', 'numpy.core.csingle', 'numpy.core
.divide', 'numpy.core.dot', 'numpy.core.double', 'numpy.core.empty', 'numpy.core
.empty_like', 'numpy.core.equal', 'numpy.core.errstate', 'numpy.core.fastCopyAnd
Transpose', 'numpy.core.finfo', 'numpy.core.float32', 'numpy.core.float64', 'num
py.core.float_', 'numpy.core.geterrobj', 'numpy.core.greater', 'numpy.core.great
er_equal', 'numpy.core.hstack', 'numpy.core.iinfo', 'numpy.core.inexact', 'numpy
.core.inf', 'numpy.core.intc', 'numpy.core.integer', 'numpy.core.invert', 'numpy
.core.isfinite', 'numpy.core.isinf', 'numpy.core.isnan', 'numpy.core.isscalar',
'numpy.core.left_shift', 'numpy.core.less', 'numpy.core.less_equal', 'numpy.core
.linspace', 'numpy.core.longdouble', 'numpy.core.maximum', 'numpy.core.multiply'
, 'numpy.core.ndarray', 'numpy.core.newaxis', 'numpy.core.not_equal', 'numpy.cor
e.number', 'numpy.core.power', 'numpy.core.product', 'numpy.core.ravel', 'numpy.
core.remainder', 'numpy.core.reshape', 'numpy.core.result_type', 'numpy.core.rig
ht_shift', 'numpy.core.rollaxis', 'numpy.core.shape', 'numpy.core.signbit', 'num
py.core.sin', 'numpy.core.single', 'numpy.core.size', 'numpy.core.sqrt', 'numpy.
core.subtract', 'numpy.core.sum', 'numpy.core.swapaxes', 'numpy.core.take', 'num
py.core.transpose', 'numpy.core.ufunc', 'numpy.core.vstack', 'numpy.core.zeros',
'numpy.deprecate', 'numpy.dtype', 'numpy.expand_dims', 'numpy.eye', 'numpy.fft.
fft', 'numpy.fft.ifft', 'numpy.histogramdd', 'numpy.integer', 'numpy.intp', 'num
py.iscomplexobj', 'numpy.lib.add_newdoc', 'numpy.lib.asfarray', 'numpy.lib.i0',
'numpy.lib.imag', 'numpy.lib.iscomplexobj', 'numpy.lib.real', 'numpy.lib.triu',
'numpy.linalg.eigvals', 'numpy.linalg.inv', 'numpy.linalg.lstsq', 'numpy.ma.MAEr
ror', 'numpy.ma.MaskedArray', 'numpy.ma.filled', 'numpy.ma.getdata', 'numpy.ma.g
etmaskarray', 'numpy.ma.make_mask_descr'
ray', 'numpy.ma.nomask', 'numpy.ndarray', 'numpy.random.rand', 'numpy.random.ran
dn', 'numpy.recarray', 'numpy_api', 'numpy_distutils', 'numpy_distutils.command.
build_flib', 'numpy_distutils.command.c
y_distutils.fcompiler', 'pkg_resources', 'pyreadline.keysyms.make_K
readline.keysyms.make_KeyP
, 'pyreadline.keysyms.make_k
ols.command.bdist_rpm', 'setuptools.command.develo
fo', 'setuptools.command.instal
'startup', 'testing.Tester', 'unittest2.case', 'urllib.error', 'urllib.parse', '
urllib.request', 'usercustomize', 'winreg']
ASKER
Even though I have used the import numpy statement in the python code and setup.py
also pip installed numpy-1.9.2rc1+mkl-cp27-no ne-win_amd 64.whl
also pip installed numpy-1.9.2rc1+mkl-cp27-no
ASKER
I must not have set it up correctly, I've installed pywin32 and followed the steps provided by clockwatcher.
C:\Python Scripts\CDF>pyinstaller -F Converter.py
125 INFO: wrote C:\Python Scripts\CDF\Converter.spec
141 INFO: Testing for ability to set icons, version resources...
280 INFO: ... resource update available
280 INFO: UPX is not available.
312 INFO: Processing hook hook-os
453 INFO: Processing hook hook-time
453 INFO: Processing hook hook-cPickle
546 INFO: Processing hook hook-_sre
671 INFO: Processing hook hook-cStringIO
779 INFO: Processing hook hook-encodings
779 INFO: Processing hook hook-codecs
2736 INFO: Processing hook hook-httplib
2750 INFO: Processing hook hook-email
2907 INFO: Processing hook hook-email.message
3353 WARNING: library python%s%s required via ctypes not found
3588 INFO: Extending PYTHONPATH with C:\Python Scripts\CDF\
3588 INFO: checking Analysis
3588 INFO: building Analysis because out00-Analysis.toc non existent
3588 INFO: running Analysis out00-Analysis.toc
3588 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
3681 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0.
21022.8_none ...
3681 WARNING: Assembly not found
3681 ERROR: Assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0. 21022.8_no ne
not found
3774 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\python.exe
3852 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0.
21022.8_none ...
3868 WARNING: Assembly not found
3868 ERROR: Assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0. 21022.8_no ne
not found
4149 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\python27.dll
4164 INFO: Analyzing C:\Anaconda\lib\site-packa ges\PyInst aller\load er\_pyi_bo ots
trap.py
4164 INFO: Processing hook hook-os
4180 INFO: Processing hook hook-site
4211 INFO: Processing hook hook-encodings
4320 INFO: Processing hook hook-time
4320 INFO: Processing hook hook-cPickle
4398 INFO: Processing hook hook-_sre
4523 INFO: Processing hook hook-cStringIO
4648 INFO: Processing hook hook-codecs
5085 INFO: Processing hook hook-httplib
5085 INFO: Processing hook hook-email
5200 INFO: Processing hook hook-email.message
5448 WARNING: library python%s%s required via ctypes not found
5636 INFO: Processing hook hook-pydoc
5776 INFO: Analyzing C:\Anaconda\lib\site-packa ges\PyInst aller\load er\pyi_imp ort
ers.py
5901 INFO: Analyzing C:\Anaconda\lib\site-packa ges\PyInst aller\load er\pyi_arc hiv
e.py
6010 INFO: Analyzing C:\Anaconda\lib\site-packa ges\PyInst aller\load er\pyi_car chi
ve.py
6135 INFO: Analyzing C:\Anaconda\lib\site-packa ges\PyInst aller\load er\pyi_os_ pat
h.py
6135 INFO: Analyzing netCDFConverter.py
7024 INFO: Processing hook hook-parser
7233 INFO: Processing hook hook-distutils
7669 INFO: Processing hook hook-sysconfig
7715 INFO: Processing hook hook-xml
7809 INFO: Processing hook hook-xml.sax
7856 INFO: Processing hook hook-pyexpat
8746 INFO: Processing hook hook-setuptools
8996 INFO: Processing hook hook-xml.dom
9010 INFO: Processing hook hook-xml.dom.domreg
9073 INFO: Processing hook hook-win32com
9073 INFO: Processing hook hook-win32com.client
9088 INFO: Processing hook hook-pythoncom
9167 INFO: Processing hook hook-pywintypes
9296 INFO: Processing hook hook-win32ui
9904 INFO: Hidden import 'codecs' has been found otherwise
9904 INFO: Hidden import 'encodings' has been found otherwise
9904 INFO: Looking for run-time hooks
9904 INFO: Analyzing rthook C:\Anaconda\lib\site-packa ges\PyInst aller\load er\rth
ooks\pyi_rth_pkgres.py
10108 INFO: Analyzing rthook C:\Anaconda\lib\site-packa ges\PyInst aller\load er\rt
hooks\pyi_rth_win32comgenp y.py
10342 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\umath.pyd
10419 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\_win32sysloade r.pyd
10842 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\netCDF4.pyd
10919 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32pdh.pyd
10997 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\lib\_compiled_ base.pyd
11090 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32pipe.pyd
11168 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\select.
pyd
11236 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\unicode
data.pyd
11329 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32evtlog.py d
11549 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\scalarmat h.pyd
11672 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\linalg\_umath_ linalg.pyd
11766 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\random\mtrand. pyd
11845 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\fft\fftpack_li te.pyd
11953 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_hashli
b.pyd
12047 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\bz2.pyd
12141 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_ssl.py
d
12282 WARNING: lib not found: MSVCR90.dll dependency of C:\Windows\system32\pyth
oncom27.dll
12391 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_ctypes
.pyd
12484 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\pyexpat
.pyd
12608 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0
.21022.8_none ...
12608 WARNING: Assembly not found
12608 ERROR: Assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0. 21022.8_no ne
not found
12608 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executabl
e
12687 INFO: Searching for assembly amd64_Microsoft.VC90.MFC_1 fc8b3b9a1e 18e3b_9.0
.21022.8_none ...
12687 INFO: Found manifest C:\Anaconda\lib\site-packa ges\Python win\Micros oft.VC9
0.MFC.manifest
12703 INFO: Searching for file mfc90.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa ges\Python win\mfc90. dll
12703 INFO: Searching for file mfc90u.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa ges\Python win\mfc90u .dll
12703 INFO: Searching for file mfcm90.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa ges\Python win\mfcm90 .dll
12703 INFO: Searching for file mfcm90u.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa ges\Python win\mfcm90 u.dll
13076 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\Pythonwin\win32ui.py d
13214 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\multiarra y.pyd
13307 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_multip
rocessing.pyd
13417 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\linalg\lapack_ lite.pyd
13494 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32trace.pyd
13635 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32api.pyd
13728 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_socket
.pyd
13838 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\_dotblas. pyd
13917 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0
.21022.8_none ...
13917 WARNING: Assembly not found
13917 ERROR: Assembly amd64_Microsoft.VC90.CRT_1 fc8b3b9a1e 18e3b_9.0. 21022.8_no ne
not found
14040 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\pywintypes27.d ll
14103 INFO: Using Python library C:\Anaconda\python27.dll
14338 INFO: Warnings written to C:\Python Scripts\CDF\build\Converte r\warnnetC DFConverte r.txt
14353 INFO: checking PYZ
14353 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
14353 INFO: building PYZ (ZlibArchive) out00-PYZ.toc
17217 INFO: checking PKG
17217 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
17217 INFO: building PKG (CArchive) out00-PKG.pkg
30741 INFO: checking EXE
30741 INFO: building because out00-EXE.toc missing or bad
30741 INFO: building EXE from out00-EXE.toc
30944 INFO: Appending archive to EXE C:\Python Scripts\CDF\dist\Converter .exe
C:\Python Scripts\CDF>pyinstaller -F Converter.py
125 INFO: wrote C:\Python Scripts\CDF\Converter.spec
141 INFO: Testing for ability to set icons, version resources...
280 INFO: ... resource update available
280 INFO: UPX is not available.
312 INFO: Processing hook hook-os
453 INFO: Processing hook hook-time
453 INFO: Processing hook hook-cPickle
546 INFO: Processing hook hook-_sre
671 INFO: Processing hook hook-cStringIO
779 INFO: Processing hook hook-encodings
779 INFO: Processing hook hook-codecs
2736 INFO: Processing hook hook-httplib
2750 INFO: Processing hook hook-email
2907 INFO: Processing hook hook-email.message
3353 WARNING: library python%s%s required via ctypes not found
3588 INFO: Extending PYTHONPATH with C:\Python Scripts\CDF\
3588 INFO: checking Analysis
3588 INFO: building Analysis because out00-Analysis.toc non existent
3588 INFO: running Analysis out00-Analysis.toc
3588 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
3681 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1
21022.8_none ...
3681 WARNING: Assembly not found
3681 ERROR: Assembly amd64_Microsoft.VC90.CRT_1
not found
3774 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\python.exe
3852 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1
21022.8_none ...
3868 WARNING: Assembly not found
3868 ERROR: Assembly amd64_Microsoft.VC90.CRT_1
not found
4149 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\python27.dll
4164 INFO: Analyzing C:\Anaconda\lib\site-packa
trap.py
4164 INFO: Processing hook hook-os
4180 INFO: Processing hook hook-site
4211 INFO: Processing hook hook-encodings
4320 INFO: Processing hook hook-time
4320 INFO: Processing hook hook-cPickle
4398 INFO: Processing hook hook-_sre
4523 INFO: Processing hook hook-cStringIO
4648 INFO: Processing hook hook-codecs
5085 INFO: Processing hook hook-httplib
5085 INFO: Processing hook hook-email
5200 INFO: Processing hook hook-email.message
5448 WARNING: library python%s%s required via ctypes not found
5636 INFO: Processing hook hook-pydoc
5776 INFO: Analyzing C:\Anaconda\lib\site-packa
ers.py
5901 INFO: Analyzing C:\Anaconda\lib\site-packa
e.py
6010 INFO: Analyzing C:\Anaconda\lib\site-packa
ve.py
6135 INFO: Analyzing C:\Anaconda\lib\site-packa
h.py
6135 INFO: Analyzing netCDFConverter.py
7024 INFO: Processing hook hook-parser
7233 INFO: Processing hook hook-distutils
7669 INFO: Processing hook hook-sysconfig
7715 INFO: Processing hook hook-xml
7809 INFO: Processing hook hook-xml.sax
7856 INFO: Processing hook hook-pyexpat
8746 INFO: Processing hook hook-setuptools
8996 INFO: Processing hook hook-xml.dom
9010 INFO: Processing hook hook-xml.dom.domreg
9073 INFO: Processing hook hook-win32com
9073 INFO: Processing hook hook-win32com.client
9088 INFO: Processing hook hook-pythoncom
9167 INFO: Processing hook hook-pywintypes
9296 INFO: Processing hook hook-win32ui
9904 INFO: Hidden import 'codecs' has been found otherwise
9904 INFO: Hidden import 'encodings' has been found otherwise
9904 INFO: Looking for run-time hooks
9904 INFO: Analyzing rthook C:\Anaconda\lib\site-packa
ooks\pyi_rth_pkgres.py
10108 INFO: Analyzing rthook C:\Anaconda\lib\site-packa
hooks\pyi_rth_win32comgenp
10342 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\umath.pyd
10419 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\_win32sysloade
10842 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\netCDF4.pyd
10919 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32pdh.pyd
10997 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\lib\_compiled_
11090 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32pipe.pyd
11168 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\select.
pyd
11236 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\unicode
data.pyd
11329 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32evtlog.py
11549 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\scalarmat
11672 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\linalg\_umath_
11766 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\random\mtrand.
11845 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\fft\fftpack_li
11953 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_hashli
b.pyd
12047 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\bz2.pyd
12141 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_ssl.py
d
12282 WARNING: lib not found: MSVCR90.dll dependency of C:\Windows\system32\pyth
oncom27.dll
12391 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_ctypes
.pyd
12484 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\pyexpat
.pyd
12608 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1
.21022.8_none ...
12608 WARNING: Assembly not found
12608 ERROR: Assembly amd64_Microsoft.VC90.CRT_1
not found
12608 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executabl
e
12687 INFO: Searching for assembly amd64_Microsoft.VC90.MFC_1
.21022.8_none ...
12687 INFO: Found manifest C:\Anaconda\lib\site-packa
0.MFC.manifest
12703 INFO: Searching for file mfc90.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa
12703 INFO: Searching for file mfc90u.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa
12703 INFO: Searching for file mfcm90.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa
12703 INFO: Searching for file mfcm90u.dll
12703 INFO: Found file C:\Anaconda\lib\site-packa
13076 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\Pythonwin\win32ui.py
13214 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\multiarra
13307 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_multip
rocessing.pyd
13417 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\linalg\lapack_
13494 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32trace.pyd
13635 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\win32api.pyd
13728 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\DLLs\_socket
.pyd
13838 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\_dotblas.
13917 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1
.21022.8_none ...
13917 WARNING: Assembly not found
13917 ERROR: Assembly amd64_Microsoft.VC90.CRT_1
not found
14040 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\pywintypes27.d
14103 INFO: Using Python library C:\Anaconda\python27.dll
14338 INFO: Warnings written to C:\Python Scripts\CDF\build\Converte
14353 INFO: checking PYZ
14353 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
14353 INFO: building PYZ (ZlibArchive) out00-PYZ.toc
17217 INFO: checking PKG
17217 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
17217 INFO: building PKG (CArchive) out00-PKG.pkg
30741 INFO: checking EXE
30741 INFO: building because out00-EXE.toc missing or bad
30741 INFO: building EXE from out00-EXE.toc
30944 INFO: Appending archive to EXE C:\Python Scripts\CDF\dist\Converter
It created an executable c:\python scripts\cdf\dist\converter .exe. What happens when you run that executable?
ASKER
This is the error
WARNING: file already exists but should not: C:\Users\123\AppData\Local \Temp\
_MEI234642\include\pyconfi g.h
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "C:\Anaconda\Lib\site-pack ages\PyIns taller\loa der\pyi_im porters.py ", line
409, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "netCDF4.pyx", line 798, in init netCDF4 (netCDF4.c:61404)
ImportError: No module named netCDF4_utils
WARNING: file already exists but should not: C:\Users\123\AppData\Local
_MEI234642\include\pyconfi
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "C:\Anaconda\Lib\site-pack
409, in load_module
module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
File "netCDF4.pyx", line 798, in init netCDF4 (netCDF4.c:61404)
ImportError: No module named netCDF4_utils
You'll probably have to build a hook file (http://pythonhosted.org/PyInstaller/#using-hook-files) to allow pyinstaller to include the hidden imports that netCDF4 is using. The following simplified sample is working for me:
cdf4pkg.py
hook-netCDF4.py
Command to create executable:
pyinstaller --additional-hooks-dir=. -F cdf4pkg.py
Results of running the executable:
cdf4pkg.py
import datetime
from netCDF4 import Dataset
if __name__ == '__main__':
d = (datetime.date.today()-datetime.timedelta(days=1)).strftime("%Y%m%d")
gfs_fcst = Dataset('http://nomads.ncep.noaa.gov:9090/dods/gens/gens{0}/gep_all_00z'.format(d))
print gfs_fcst
hook-netCDF4.py
hiddenimports = ['numpy', 'netCDF4_utils', 'netcdftime']
Command to create executable:
pyinstaller --additional-hooks-dir=. -F cdf4pkg.py
16 INFO: wrote C:\Users\mark\testcdf\cdf4pkg.spec
30 INFO: Testing for ability to set icons, version resources...
78 INFO: ... resource update available
78 INFO: UPX is not available.
94 INFO: Processing hook hook-os
219 INFO: Processing hook hook-time
219 INFO: Processing hook hook-cPickle
296 INFO: Processing hook hook-_sre
421 INFO: Processing hook hook-cStringIO
516 INFO: Processing hook hook-encodings
530 INFO: Processing hook hook-codecs
917 INFO: Extending PYTHONPATH with C:\Users\mark\testcdf
917 INFO: checking Analysis
917 INFO: building Analysis because out00-Analysis.toc non existent
917 INFO: running Analysis out00-Analysis.toc
917 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
1121 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none ...
1121 INFO: Found manifest C:\WINDOWS\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b.manifest
1121 INFO: Searching for file msvcr90.dll
1121 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcr90.dll
1121 INFO: Searching for file msvcp90.dll
1121 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcp90.dll
1121 INFO: Searching for file msvcm90.dll
1121 INFO: Found file C:\WINDOWS\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b\msvcm90.dll
1246 INFO: Analyzing C:\Users\mark\testcdf\lib\site-packages\PyInstaller\loader\_pyi_bootstrap.py
1246 INFO: Processing hook hook-os
1262 INFO: Processing hook hook-site
1292 INFO: Processing hook hook-encodings
1434 INFO: Processing hook hook-time
1434 INFO: Processing hook hook-cPickle
1512 INFO: Processing hook hook-_sre
1637 INFO: Processing hook hook-cStringIO
1762 INFO: Processing hook hook-codecs
2214 INFO: Processing hook hook-pydoc
2339 INFO: Processing hook hook-email
2402 INFO: Processing hook hook-httplib
2434 INFO: Processing hook hook-email.message
2512 INFO: Analyzing C:\Users\mark\testcdf\lib\site-packages\PyInstaller\loader\pyi_importers.py
2559 INFO: Analyzing C:\Users\mark\testcdf\lib\site-packages\PyInstaller\loader\pyi_archive.py
2621 INFO: Analyzing C:\Users\mark\testcdf\lib\site-packages\PyInstaller\loader\pyi_carchive.py
2675 INFO: Analyzing C:\Users\mark\testcdf\lib\site-packages\PyInstaller\loader\pyi_os_path.py
2675 INFO: Analyzing cdf4pkg.py
2675 INFO: Processing hook hook-netCDF4
3394 INFO: Processing hook hook-parser
3519 INFO: Processing hook hook-distutils
4004 INFO: Processing hook hook-setuptools
4332 INFO: Processing hook hook-sysconfig
4364 INFO: Processing hook hook-xml
4411 INFO: Processing hook hook-xml.sax
4457 INFO: Processing hook hook-pyexpat
4457 INFO: Processing hook hook-xml.dom
4473 INFO: Processing hook hook-xml.dom.domreg
4966 INFO: Hidden import 'codecs' has been found otherwise
4966 INFO: Hidden import 'encodings' has been found otherwise
4966 INFO: Looking for run-time hooks
4966 INFO: Analyzing rthook C:\Users\mark\testcdf\lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py
6216 INFO: Using Python library C:\WINDOWS\system32\python27.dll
6325 INFO: Warnings written to C:\Users\mark\testcdf\build\cdf4pkg\warncdf4pkg.txt
6341 INFO: checking PYZ
6341 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
6341 INFO: building PYZ (ZlibArchive) out00-PYZ.toc
9020 INFO: checking PKG
9020 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
9020 INFO: building PKG (CArchive) out00-PKG.pkg
24394 INFO: checking EXE
24394 INFO: rebuilding out00-EXE.toc because cdf4pkg.exe missing
24394 INFO: building EXE from out00-EXE.toc
24394 INFO: Appending archive to EXE C:\Users\mark\testcdf\dist\cdf4pkg.exe
Results of running the executable:
C:\Users\mark\testcdf\dist>cdf4pkg.exe
WARNING: file already exists but should not: C:\Users\mark\AppData\Local\Temp\_M
EI137402\include\pyconfig.h
<type 'netCDF4.Dataset'>
root group (NETCDF3_CLASSIC data model, file format DAP2):
title: GENS all members fcst starting from 00Z21feb2015, downloaded Feb 21 0
6:09 UTC
Conventions: COARDS
GrADS
dataType: Grid
history: Sat Feb 21 06:26:54 GMT 2015 : imported by GrADS Data Server 2.0
dimensions(sizes): ens(21), lat(181), lev(26), lon(360), time(65)
variables(dimensions): float64 ←[4mens←[0m(ens), float64 ←[4mtime←[0m(time),
float64 ←[4mlev←[0m(lev), float64 ←[4mlat←[0m(lat), float64 ←[4mlon←[0m(lon), f
loat32 ←[4mabsvprs←[0m(ens,time,lev,lat,lon), float32 ←[4mno4lftxsfc←[0m(ens,tim
e,lat,lon), float32 ←[4mno5wava500mb←[0m(ens,time,lat,lon), float32 ←[4mno5wavh5
00mb←[0m(ens,time,lat,lon), float32 ←[4macpcpsfc←[0m(ens,time,lat,lon), float32
←[4malbdosfc←[0m(ens,time,lat,lon), float32 ←[4mapcpsfc←[0m(ens,time,lat,lon), f
loat32 ←[4mcapesfc←[0m(ens,time,lat,lon), float32 ←[4mcape180_0mb←[0m(ens,time,l
at,lon), float32 ←[4mcfrzrsfc←[0m(ens,time,lat,lon), float32 ←[4mcicepsfc←[0m(en
s,time,lat,lon), float32 ←[4mcinsfc←[0m(ens,time,lat,lon), float32 ←[4mcin180_0m
b←[0m(ens,time,lat,lon), float32 ←[4mclwmrprs←[0m(ens,time,lev,lat,lon), float32
←[4mcpratsfc←[0m(ens,time,lat,lon), float32 ←[4mcrainsfc←[0m(ens,time,lat,lon),
...
ASKER
I'm now getting an error cannot import name netCDF4_utils
WARNING: file already exists but should not: C:\Users\abc\AppData\Local \Temp\
_MEI290202\include\pyconfi g.h
Traceback (most recent call last):
File "<string>", line 6, in <module>
ImportError: cannot import name netCDF4_utils
WARNING: file already exists but should not: C:\Users\abc\AppData\Local
_MEI290202\include\pyconfi
Traceback (most recent call last):
File "<string>", line 6, in <module>
ImportError: cannot import name netCDF4_utils
Are you using the hook that I provided? It should include netCDF4_utils. It did in my build. I was getting the error before I included it. I included it and then got an error about a missing netcdftime. Included that one in the hook too, and it built fine.
BTW... also make sure to delete your dist and build subdirectories before each rebuild. It seems to have an issue with reusing stale files.
ASKER
Thanks for your comments.
I deleted both the directories and tried again unfortunately the same error as above. I'm using the hooks example you provided.
I've installed netCDF4-1.1.3-cp27-none-wi n_amd64.wh l from this site http://www.lfd.uci.edu/~gohlke/pythonlibs/. Does netcdf4_utils exist in another library? When running in Anaconda import of netcdf4_utils wasn't required.
I'm wondering whether the link to msvcr90.dll is set up properly. The three files (msvcm90.dll/msvcp90.dll/m svcr90.dll ) exist under the Anaconda /Microsoft .VC90.CRT folder. When running the hooks command, a number of lib not found warning messages appear for msvcr90.dll.
I followed http://py2exe.org/index.cgi/Tutorial by updating my setup file when trying to use py2exe I couldn't find the manifest file for msvcr90.dll version 9.0.21022.8. How does pyinstaller differ?
I've noticed the files don't exist in the below folder anymore C:\Windows\winsxs\amd64_mi crosoft.vc 90.openmp_ 1fc8b3b9a1 e18e3b_9.0 .21022.8_n one_a53255 51f9d85633 and is replaced by vcomp90.dll
I deleted both the directories and tried again unfortunately the same error as above. I'm using the hooks example you provided.
I've installed netCDF4-1.1.3-cp27-none-wi
I'm wondering whether the link to msvcr90.dll is set up properly. The three files (msvcm90.dll/msvcp90.dll/m
I followed http://py2exe.org/index.cgi/Tutorial by updating my setup file when trying to use py2exe I couldn't find the manifest file for msvcr90.dll version 9.0.21022.8. How does pyinstaller differ?
I've noticed the files don't exist in the below folder anymore C:\Windows\winsxs\amd64_mi
The missing MSVC 9 runtime really shouldn't be all that big of a deal. At least it's not that big of a deal in the bigger scheme of getting your missing netCDF4 packaged with your executable. Worst case with the MSVC runtime is you can distribute it along with your executable (http://www.microsoft.com/en-us/download/details.aspx?id=5582). So it definitely shouldn't be anything to worry about at this stage.
I created mine in a clean virtualenv of a 64-bit python 2.7.8. Here are the rough steps that I went through:
Create a virtualenv:
c:\python27\scripts\virtua lenv myenv
Activate it:
cd myenv
.\scripts\activate
Download and pip install the 64-bit wheels for cython, numpy, h5py and netcdf4 from http://www.lfd.uci.edu/~gohlke/pythonlibs/
pip install C:\Users\mark\Downloads\Cy thon-0.22- cp27-none- win_amd64. whl
pip install C:\Users\mark\Downloads\nu mpy-1.8.2+ mkl-cp27-n one-win_am d64.whl
pip install C:\Users\mark\Downloads\h5 py-2.4.0-c p27-none-w in_amd64.w hl
pip install C:\Users\mark\Downloads\ne tCDF4-1.1. 4-cp27-non e-win_amd6 4.whl
Install pywin32 into the virtualenv with the following directions: http://www.activestate.com/blog/2010/12/tips-activepython-pywin32-and-virtualenv
Pip install pyinstaller
pip install pyinstaller
Add the hook-netCDF4.py file
Copy your program into your virtualenv.
Run pyinstaller on it.
I created mine in a clean virtualenv of a 64-bit python 2.7.8. Here are the rough steps that I went through:
Create a virtualenv:
c:\python27\scripts\virtua
Activate it:
cd myenv
.\scripts\activate
Download and pip install the 64-bit wheels for cython, numpy, h5py and netcdf4 from http://www.lfd.uci.edu/~gohlke/pythonlibs/
pip install C:\Users\mark\Downloads\Cy
pip install C:\Users\mark\Downloads\nu
pip install C:\Users\mark\Downloads\h5
pip install C:\Users\mark\Downloads\ne
Install pywin32 into the virtualenv with the following directions: http://www.activestate.com/blog/2010/12/tips-activepython-pywin32-and-virtualenv
Pip install pyinstaller
pip install pyinstaller
Add the hook-netCDF4.py file
Copy your program into your virtualenv.
Run pyinstaller on it.
ASKER
I'm unclear about downloading/creating the virtual environment and activating it. Could you provide more info pls.
I've found virtualenv‑12.0.7‑py2.py3‑ none‑any.w hl and will download and install.
I've found virtualenv‑12.0.7‑py2.py3‑
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.