Solved

How to run Python script on Windows machines

Posted on 2015-02-09
23
431 Views
Last Modified: 2015-03-03
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
0
Comment
Question by:AndyC1000
  • 10
  • 7
  • 5
  • +1
23 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 40599895
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.
0
 
LVL 23

Expert Comment

by:Michael74
ID: 40599901
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40605145
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...

pip install pyinstaller

Open in new window


will install pyinstaller.  Once pyinstaller is installed:
pyinstaller -F yourscript.py

Open in new window


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.
0
 

Author Comment

by:AndyC1000
ID: 40620459
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\ModulesDownloaded\netCDF4-1.1.3-cp27-none-win_amd64.whl 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.
0
 
LVL 23

Expert Comment

by:Michael74
ID: 40620465
Are you running this in Cygwin?
0
 

Author Comment

by:AndyC1000
ID: 40620470
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.
0
 
LVL 23

Expert Comment

by:Michael74
ID: 40620475
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
0
 

Author Comment

by:AndyC1000
ID: 40620477
I'm using python 2.7.
0
 

Author Comment

by:AndyC1000
ID: 40620479
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.Exceptions', 'IronPythonConsole',
 'Numeric', 'Pyrex.Compiler.Main', 'System', 'System.Windows.Forms.Clipboard', '
__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_nested', 'numpy.compat.asstr', 'numpy.comp
at.basestring', 'numpy.compat.bytes', 'numpy.compat.integer_types', '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.complexfloating', '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.cpuinfo', 'numpy_distutils.cpuinfo', 'nump
y_distutils.fcompiler', 'pkg_resources', 'pyreadline.keysyms.make_KeyPress', 'py
readline.keysyms.make_KeyPress_from_keydescr', 'pyreadline.keysyms.make_keyinfo'
, 'pyreadline.keysyms.make_keysym', 'setuptools', 'setuptools.command', 'setupto
ols.command.bdist_rpm', 'setuptools.command.develop', 'setuptools.command.egg_in
fo', 'setuptools.command.install', 'setuptools.command.sdist', 'sitecustomize',
'startup', 'testing.Tester', 'unittest2.case', 'urllib.error', 'urllib.parse', '
urllib.request', 'usercustomize', 'winreg']
0
 
LVL 23

Expert Comment

by:Michael74
ID: 40620484
0
 

Author Comment

by:AndyC1000
ID: 40620489
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-none-win_amd64.whl
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 23

Expert Comment

by:Michael74
ID: 40620492
May want to give pyinstaller a try

https://github.com/pyinstaller/pyinstaller/wiki
0
 

Author Comment

by:AndyC1000
ID: 40620507
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_1fc8b3b9a1e18e3b_9.0.
21022.8_none ...
3681 WARNING: Assembly not found
3681 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
not found
3774 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\python.exe
3852 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.
21022.8_none ...
3868 WARNING: Assembly not found
3868 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
not found
4149 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\python27.dll
4164 INFO: Analyzing C:\Anaconda\lib\site-packages\PyInstaller\loader\_pyi_boots
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-packages\PyInstaller\loader\pyi_import
ers.py
5901 INFO: Analyzing C:\Anaconda\lib\site-packages\PyInstaller\loader\pyi_archiv
e.py
6010 INFO: Analyzing C:\Anaconda\lib\site-packages\PyInstaller\loader\pyi_carchi
ve.py
6135 INFO: Analyzing C:\Anaconda\lib\site-packages\PyInstaller\loader\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-packages\PyInstaller\loader\rth
ooks\pyi_rth_pkgres.py
10108 INFO: Analyzing rthook C:\Anaconda\lib\site-packages\PyInstaller\loader\rt
hooks\pyi_rth_win32comgenpy.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\_win32sysloader.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.pyd
11549 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\scalarmath.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_lite.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_1fc8b3b9a1e18e3b_9.0
.21022.8_none ...
12608 WARNING: Assembly not found
12608 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
 not found
12608 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executabl
e
12687 INFO: Searching for assembly amd64_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0
.21022.8_none ...
12687 INFO: Found manifest C:\Anaconda\lib\site-packages\Pythonwin\Microsoft.VC9
0.MFC.manifest
12703 INFO: Searching for file mfc90.dll
12703 INFO: Found file C:\Anaconda\lib\site-packages\Pythonwin\mfc90.dll
12703 INFO: Searching for file mfc90u.dll
12703 INFO: Found file C:\Anaconda\lib\site-packages\Pythonwin\mfc90u.dll
12703 INFO: Searching for file mfcm90.dll
12703 INFO: Found file C:\Anaconda\lib\site-packages\Pythonwin\mfcm90.dll
12703 INFO: Searching for file mfcm90u.dll
12703 INFO: Found file C:\Anaconda\lib\site-packages\Pythonwin\mfcm90u.dll
13076 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\Pythonwin\win32ui.pyd
13214 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\numpy\core\multiarray.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_1fc8b3b9a1e18e3b_9.0
.21022.8_none ...
13917 WARNING: Assembly not found
13917 ERROR: Assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_none
 not found
14040 WARNING: lib not found: MSVCR90.dll dependency of C:\Anaconda\lib\site-pac
kages\win32\pywintypes27.dll
14103 INFO: Using Python library C:\Anaconda\python27.dll
14338 INFO: Warnings written to C:\Python Scripts\CDF\build\Converter\warnnetCDFConverter.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
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40620551
It created an executable c:\python scripts\cdf\dist\converter.exe.  What happens when you run that executable?
0
 

Author Comment

by:AndyC1000
ID: 40624901
This is the error

WARNING: file already exists but should not: C:\Users\123\AppData\Local\Temp\
_MEI234642\include\pyconfig.h
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "C:\Anaconda\Lib\site-packages\PyInstaller\loader\pyi_importers.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
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40625025
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
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

Open in new window


hook-netCDF4.py
hiddenimports = ['numpy', 'netCDF4_utils', 'netcdftime']

Open in new window


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

Open in new window



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),
...

Open in new window

0
 

Author Comment

by:AndyC1000
ID: 40627305
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\pyconfig.h
Traceback (most recent call last):
  File "<string>", line 6, in <module>
ImportError: cannot import name netCDF4_utils
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40627311
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.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40627315
BTW... also make sure to delete your dist and build subdirectories before each rebuild.   It seems to have an issue with reusing stale files.
0
 

Author Comment

by:AndyC1000
ID: 40627384
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-win_amd64.whl 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/msvcr90.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_microsoft.vc90.openmp_1fc8b3b9a1e18e3b_9.0.21022.8_none_a5325551f9d85633 and is replaced by vcomp90.dll
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 40627417
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\virtualenv 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\Cython-0.22-cp27-none-win_amd64.whl
pip install C:\Users\mark\Downloads\numpy-1.8.2+mkl-cp27-none-win_amd64.whl
pip install C:\Users\mark\Downloads\h5py-2.4.0-cp27-none-win_amd64.whl
pip install C:\Users\mark\Downloads\netCDF4-1.1.4-cp27-none-win_amd64.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.
0
 

Author Comment

by:AndyC1000
ID: 40627425
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.whl and will download and install.
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 40627459
You can read up on virtualenv's here (https://virtualenv.pypa.io/en/latest/).  But here's a two minute intro.  

You install it into your main python with:

 pip install virtualenv

That places a program called virtualenv in your python .\scripts subdirectory.  Running that program:

\python27\scripts\virtualenv someenv

Creates a subdirectory called someenv.  That subdirectory contains a clean python install in it.  Basically, a python install that just includes pip and setuptools.  You activate that environment (under windows) by running the activate.bat script that it places in the .\someenv\scripts subdirectory.  

.\someenv\scripts\activate.bat

That script adjusts your path so your virtualenv's python, pip, easy_install are hit first.  

Honestly, you shouldn't really need it.  But for distribution purposes it might be easier to start clean (rather than with a huge anaconda install which has everything and the kitchen sink in it).

Create your virtualenv.  Move your script into it.  Try and run it.  Install dependencies as you need them into your virtualenv until your program runs successfully.  Keep track of your required dependencies as you install them-- as they'll give you a good idea of what pyinstaller (or py2exe) might need to include.  

Anyway... wish you the best of luck.  It seems to be working for me.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now