{"id":148,"date":"2015-06-12T02:02:19","date_gmt":"2015-06-12T10:02:19","guid":{"rendered":"https:\/\/www.actinia.me\/?p=148"},"modified":"2016-04-10T17:55:26","modified_gmt":"2016-04-11T01:55:26","slug":"problems-about-compiling-with-pyinstaller","status":"publish","type":"post","link":"https:\/\/www.actinia.me\/?p=148","title":{"rendered":"Problems about compiling (with pyinstaller)."},"content":{"rendered":"<p>It&#8217;s really a huge work for me this week to compile my nlk program with new interface into exe. I ran into a lot of problems. Fortunately, I managed to solve them through Googling. I will note some of the major problems below.<\/p>\n<p><strong>1.No module named *** :<\/strong><br \/>\nAt firse I was trying py2exe. However, a lot of modules can not be included in py2exe. So I turned to pyinstaller. I can get a exe file with pyinstaller, but when i ran it, a command window flashed out and report &#8220;No mudule named ***&#8221;. I included the missing files in the bat file one by one according to the reports. That leads my bat file to be very\u00a0lengthy:<\/p>\n<pre><code>pyinstaller -F -w myscript.py --hidden-import=scipy.special._ufuncs_cxx --hidden-import=scipy.integrate --hidden-import=scipy.integrate.quadrature --hidden-import=scipy.integrate.odepack --hidden-import=scipy.integrate._odepack --hidden-import=scipy.integrate.quadpack --hidden-import=scipy.integrate._quadpack --hidden-import=scipy.integrate.quadpack --hidden-import=scipy.integrate._ode --hidden-import=scipy.integrate.vode --hidden-import=scipy.integrate._dop --hidden-import=scipy.integrate.lsoda\r\n pause<\/code><\/pre>\n<p>Most of the files are from scipy.integrate. I guess there should be a simpler method to include the whole folder with one command which i don&#8217;t know at the moment.<\/p>\n<p>after all these test-and-modify, I finally got an &#8220;executable&#8221; executable file.<\/p>\n<p><strong>2. get rid of the black window on running .exe:<\/strong> this is very simple. Just as the bat file shown above, a simple &#8220;-w&#8221; solved this problem.<\/p>\n<p><strong>3. file already exists but should not: ***pyconfig.h:<\/strong><br \/>\nBefore my program opened its window, there was\u00a0another window which reports: file already exists but should not: *****(a path which i can not remember now)\/pyconfig.h.<br \/>\nI found the solution <span style=\"color: #3366ff;\"><a style=\"color: #3366ff;\" title=\"here\" href=\"http:\/\/stackoverflow.com\/a\/19163950\/4431612\">here<\/a><\/span>:<br \/>\nwhen I start the compiling Bat file, a .spec file which contains the compiling configuration information was generated in the same folder with the file name &#8220;myscript(.spec)&#8221;. What i have to do is to modify\u00a0this spec file. just like the answer in the above link, I have to add after\u00a0a=Analysis something like this :<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\"><code><span class=\"kwd\">for<\/span><span class=\"pln\"> d <\/span><span class=\"kwd\">in<\/span><span class=\"pln\"> a<\/span><span class=\"pun\">.<\/span><span class=\"pln\">datas<\/span><span class=\"pun\">:<\/span>\r\n    <span class=\"kwd\">if<\/span> <span class=\"str\">'pyconfig'<\/span> <span class=\"kwd\">in<\/span><span class=\"pln\"> d<\/span><span class=\"pun\">[<\/span><span class=\"lit\">0<\/span><span class=\"pun\">]:<\/span><span class=\"pln\"> \r\n        a<\/span><span class=\"pun\">.<\/span><span class=\"pln\">datas<\/span><span class=\"pun\">.<\/span><span class=\"pln\">remove<\/span><span class=\"pun\">(<\/span><span class=\"pln\">d<\/span><span class=\"pun\">)<\/span>\r\n        <span class=\"kwd\">break<\/span><\/code><\/pre>\n<p>Then, I have to modify the bat file. Because All the required\u00a0compiling configurations are in the spec file now, I should not re-run the previous bat file to over write spec, but\u00a0call the spec file directly in bat. The new bat file is very short:<\/p>\n<pre>pyinstaller nlk.spec\r\n pause<\/pre>\n<p><strong>4.myscript.exe not a valid win32 application:<\/strong><\/p>\n<p>My exe worked\u00a0fine\u00a0on\u00a0win64. But when I ran it on a 32bit XP, it reported &#8220;myscript.exe\u00a0not a valid win32 application&#8221;.<\/p>\n<p>My script was written and compiled in a 64-bit version Winpython. It seems that I have to install a new 32-bit winpython.<\/p>\n<p>So I installed 32-bit winpython and installed qtutil and pyinstaller which was not contained in winpython.I compiled the script in 32wp, and ran it again. Still, it reported the same error. Then I found that although I had unregistered the 64wp and registered the 32wp, the path in\u00a0environment variable still point to the 64wp.So I modified the\u00a0environment variable to 32wp and tried again. This time the compiling comand window reported a new error:<\/p>\n<p><strong>5.pyinstaller distributionnotfound:<\/strong><\/p>\n<p><a title=\"Solution\" href=\"http:\/\/stackoverflow.com\/a\/29609088\/4431612\"><span style=\"color: #3366ff;\">Solution<\/span><\/a>\u00a0to this error is:<\/p>\n<p>First, up date pip to latest version:<\/p>\n<pre class=\"lang-py prettyprint prettyprinted\"><code><span class=\"pln\">python <\/span><span class=\"pun\">-<\/span><span class=\"pln\">m pip install <\/span><span class=\"pun\">--<\/span><span class=\"pln\">upgrade <\/span><span class=\"pun\">--<\/span><span class=\"pln\">force pip<\/span><\/code><\/pre>\n<p>Second, re-install pyinstaller with the new pip (I&#8217;m not sure if this step is\u00a0necessary).<\/p>\n<p>Third, compile with the new pyinstaller.<\/p>\n<p>&nbsp;<\/p>\n<p>After all these strivings, I finally got an executable file that worked perfectly on both 64bit and 32bit windows systems. Special thanks to GOOGLE without which I might\u00a0never complete my work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s really a huge work for me this week to compile my nlk program with new interface into exe. I ran into a lot of problems. Fortunately, I managed to solve them through Googling. I will note some of the major problems below. 1.No module named *** : At firse I was trying py2exe. However, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/148"}],"collection":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":15,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/www.actinia.me\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.actinia.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}