-1

When I run my code in Pycharm it parses my Excel files and merges everything correctly in the IDE. However I build it into an executable using cx_Freeze it stops working. When I double click the executable it doesn't anything. A black console window flashes quickly. What gives. There is no stack trace or error in Pycharm.

Here is my code for reference:

[In:]

import numpy as np
import pandas as pd

 #finds the path to a users pc.
userHome = os.path.expanduser('~')
directory = userHome + '/Desktop/Parsing Script/ParsingScriptOutputFile/'
workerList= (directory+'employeeList.csv')
managerList = (userHome+'/Parsing Script/ParsingScriptOutputFile/managerList.XLSX')

 # specify 32 columns, no headers
employee = pd.read_csv(workerList, usecols=range(32), header=None,  sep=",",engine='python') # read in the data
original_rows = employee.shape[0] # original number of rows
managers = pd.read_excel(managerList)
managers= managers[['Cost Center','Profit Center','User ID', 'Description','Email address','Person Responsible']]

# Left join so that the rows that do not match are not dropped from employee
# data
merged_df = pd.merge(employee, managers, on='key', how='left')

# Number of rows should be unchanged
# This should print out True
print(merged_df.shape[0] == original_rows)
#File called merged_data.csv returned to ParsingScriptOutputFile
return merged_df.to_csv(directory+'merged_data.csv', index=False, encoding='utf-8') # Save    

@ sideffect0 (thanks for the advice) Full traceback

Traceback (most recent call last):
  File "C:\Python\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 12, in <module>

    __import__(name + "__init__")
  File "C:\Python\lib\site-packages\cx_Freeze\initscripts\Console.py", line      24, in <module>
    exec(code, m.__dict__)
  File "csvProject1.py", line 3, in <module>
  File "C:\Python\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
  File "C:\Python\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
  File "C:\Python\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
     File "C:\Python\lib\site-packages\numpy\core\__init__.py", line 36, in <module>
    from . import numeric
   File "C:\Python\lib\site-packages\numpy\core\numeric.py", line 1842, in <module>
    from .arrayprint import array2string, get_printoptions, set_printoptions
  File "C:\Python\lib\site-packages\numpy\core\arrayprint.py", line 24, in <module>
from .fromnumeric import ravel
  File "C:\Python\lib\site-packages\numpy\core\fromnumeric.py", line 15, in <module>
    from . import _methods
ImportError: cannot import name '_methods'
greenbai
  • 13
  • 5
  • are the file paths the same? asking because you could be attempting the `exe` on another machine? – WhatsThePoint Feb 13 '17 at 16:19
  • what happens if you run the `exe` from the command line? – asongtoruin Feb 13 '17 at 16:19
  • 2
    I think you are in windows, open command prompt ( Win + R -> cmd), run the program from there, you will get traceback with details, then add the traceback in this question – Renjith Thankachan Feb 13 '17 at 16:19
  • File paths are the same, @asongtoruin Same thing, Yes this is a method part of a larger parsing script. However I have taken this method out of the larger script and the rest of thescript runs fine. I tried building only this code using cx_Freeze and it won't work. And it still works in pycharm. – greenbai Feb 13 '17 at 16:25
  • @sideeffect0 thanks for the tip. – greenbai Feb 13 '17 at 16:32
  • may help [from . import _methods ImportError: cannot import name '_methods' in cx-freeze python](http://stackoverflow.com/questions/41735413/from-import-methods-importerror-cannot-import-name-methods-in-cx-freeze-p) – chickity china chinese chicken Feb 13 '17 at 17:27
  • @downshift. Thanks for that link. Your fix worked! I think it was a error with a module not installing correctly. Coupled with a corrupted numpy installation. – greenbai Feb 14 '17 at 09:48
  • That's great news @greenbai, I'm really glad to hear you fixed it – chickity china chinese chicken Feb 14 '17 at 17:25

1 Answers1

1

The issue was a module not correctly installing In the setup.py file I used this code from this stackoverflow answer that @downshift linked me. Also I found that I had a corrupted installation of numpy. So I did a quick uninstall and re-install of that. Rebuilt the script into an executable and it worked perfectly.

To get the full traceback I navigated to the executable in the command line and typed in the filename. A quicker way of doing this is hold down altand right clicking on the file that contains your exe, then click open open command window this will open cmd at the file location for you. Run your program for there to get the traceback

Community
  • 1
  • 1
greenbai
  • 13
  • 5