Problem with creating an .exe out of my Python script via Pyinstaller - python

I'm trying to create an exe out of my Python script. After a long journey of problem solving, I finally made it with Pyinstaller. I got a build folder, a dist folder, and the needed exe file.
Now, when I try to run the program, it doesn't work, although it does work in my IDE, PyCharm. If I just click on it, the cmd just opens for a ms and closes right away. If I start it via the cmd, it shows the error you can see below.
Normally there should be a main_window generated by my script, and like I said, it works when I start it from pycharm directly, so the code shouldn't be the problem.
I need the program on another PC without Pycharm at all, so I definitely need this exe file. I hope you can help me. Thanks in advance!
This is the error:
C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_>main_.exe
Traceback (most recent call last):
File "main_.py", line 7, in <module>
import torch
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\__init__.py", line 643, in <module>
from .functional import * # noqa: F403
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\functional.py", line 6, in <module>
import torch.nn.functional as F
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\__init__.py", line 1, in <module>
from .modules import * # noqa: F403
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\modules\__init__.py", line 2, in <module>
from .linear import Identity, Linear, Bilinear, LazyLinear
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\modules\linear.py", line 6, in <module>
from .. import functional as F
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\nn\functional.py", line 11, in <module>
from .._jit_internal import boolean_dispatch, _overload, BroadcastingList1, BroadcastingList2, BroadcastingList3
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\_jit_internal.py", line 28, in <module>
import torch.package._mangling as package_mangling
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\package\__init__.py", line 11, in <module>
from .package_exporter import EmptyMatchError, PackageExporter, PackagingError
File "C:\Users\messlaptop\PycharmProjects\Source_code\dist\main_\torch\package\package_exporter.py", line 5, in <module>
import pickletools
ModuleNotFoundError: No module named 'pickletools'
[8896] Failed to execute script 'main_' due to unhandled exception!

Related

importing pywinauto.application throws error while trying to run using python 3.5.4

I was trying to execute the following command on windows 10 machine using python 3.5.4,
from pywinauto.application import Application
Following is the error which i was receiving
Traceback (most recent call last):
File "C:/Users/bizact/Desktop/PSAV/test.py", line 1, in <module>
from pywinauto.application import Application
File "C:\Program Files\Python35\lib\site-packages\pywinauto\__init__.py", line 72, in <module>
from . import findwindows
File "C:\Program Files\Python35\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Program Files\Python35\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Program Files\Python35\lib\site-packages\pywinauto\controls\uiawrapper.py", line 46, in <module>
from ..uia_defines import IUIA
File "C:\Program Files\Python35\lib\site-packages\pywinauto\uia_defines.py", line 35, in <module>
import comtypes.client
File "C:\Program Files\Python35\lib\site-packages\comtypes\client\__init__.py", line 33, in <module>
gen_dir = _find_gen_dir()
File "C:\Program Files\Python35\lib\site-packages\comtypes\client\_code_cache.py", line 71, in _find_gen_dir
result = os.path.abspath(gen_path[-1])
IndexError: list index out of range
Is there a way i can fix this ?
Try running the script with administrative privileges. Just by looking at the traceback it looks like some cached files that pywinauto import tried to write but later on it wasn't found, and generally the script can't write the file due to permissions. If the above don't work, try installing python somewhere else (C:/Python with full privileges in order to isolate the issue)
This is comtypes issue. It will be fixed soon (EDIT: fixed in comtypes==1.1.7). You can downgrade to one of previous versions: pip install comtypes==1.1.2. Or run script as Administrator as Rodolfo suggested (disabling UAC may not help, need to say explicitly to "run as Administrator" by popup menu).

py2exe: run the compiled .exe, got error: type object 'pandas._libs.tslib._TSObject' has no attribute...__'

I use py2exe to compile python script. The python script runs without any error before compiling.
below is the setup.py
from distutils.core import setup
import py2exe, sys, os
import matplotlib
import numpy
from glob import glob
sys.argv.append('py2exe')
datafiles = [("Microsoft.VC90.CRT", glob(r'C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_99b61f5e8371c1d4\*.*'))]
datafiles.extend(matplotlib.get_py2exe_datafiles())
setup(windows=['Run.py'], data_files= datafiles, options={"py2exe": {"includes": ["matplotlib"]}})
In the run.py, I imported pandas. Pandas is used in a function as below
import pandas
def PossDist(Iterations, AssumptionFolder, ResultFolder, SampledResult):
SampledLoss = pandas.read_csv(SampledResult)
d= pandas.pivot_table(...)
The compile finished successfully without error.
When I run the compiled run.exe, I got error as below.
Traceback (most recent call last):
File "Run.py", line 6, in
File "xlwings__init__.pyc", line 34, in
File "xlwings\main.pyc", line 1727, in
File "xlwings\conversion__init__.pyc", line 3, in
File "pandas__init__.pyc", line 26, in
Main Features
File "pandas_libs__init__.pyc", line 4, in
File "pandas_libs\tslib.pyc", line 12, in
File "pandas_libs\tslib.pyc", line 10, in __load
File "pandas_libs\tslib.pyx", line 1514, in init pandas._libs.tslib
AttributeError: type object 'pandas._libs.tslib._TSObject' has no attribute 'reduce_cython'
Anyone have any clue?
Is there other way to let others run my python script on pc without python installed?
Thanks,

I can't make anaconda work on windows by importing pandas

I am new to Python and am trying to use anaconda to do some data analysis. I am using Python 3.6.2 along with the geany text editor.
First, I'm trying to execute a file call panda.py which only contains import pandas as dp.
When I configure geany with a working directory of C:\Users\Anaconda3\python, I get the following error:
Traceback (most recent call last):
File "panda.py", line 1, in <module>
import pandas as dp
File "C:\Users\Anaconda3\lib\site-packages\pandas\__init__.py", line 13, in <module>
__import__(dependency)
File "C:\Users\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 35, in <module>
from . import _internal # for freeze programs
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\_internal.py", line 18, in <module>
from .numerictypes import object_
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 962, in <module>
_register_types()
File "C:\Users\Anaconda3\lib\site-packages\numpy\core\numerictypes.py", line 958, in _register_types
numbers.Integral.register(integer)
AttributeError: module 'numbers' has no attribute 'Integral'
The same error also occurs when I enter the following at the command prompt:
C:\Users\Anaconda3\python.exe C:\Users\Documents\python_work\panda.py
However, if I execute C:\Users\David\Anaconda3\python.exe and then enter import pandas as dp in the REPL, it appears to load without error.
Any idea how I can fix this so I can use anaconda with geany?
[SOLVED] John below ask if I had a file called numbers.py in my directory which made me realize I named an exercise I previously did as numbers.py. Once I removed it, the error went away (I tested it further by adding a file with the name again and the error returned).
I'm new to the stack over flow community. Let me know if there's anything else I need to do to close out this question.
Also thanks to chb for the edits to my original question the format looks much easier to read.
Disclaimer: python on windows is not something I know about
You know that C:\Users\David\Anaconda3\python.exe when run standalone knows how to import pandas, so your setup is fine - you have everything installed that you need, and in the correct locations.
Given that, you can look at two issues: gearny setup, and general setup. I noticed that python and pandas is installed under C:\Users\Anaconda3, while your program is under C:\Users\Documents\python_work, and we also have C:\Users\David - could it be permissions issues?

ImportError: No module named fixedpickle when running PyDsTool on Windows 7

I have downloaded PyDsTool for Windows. And I believe I have pointed python in the correct location. But I get the following error
from PyDSTool import *
Traceback (most recent call last):
File "<ipython-input-1-7b811358a37e>", line 1, in <module>
from PyDSTool import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\__init__.py", line 85, in <module>
from .Events import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\Events.py", line 13, in <module>
from .Variable import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\Variable.py", line 10, in <module>
from .utils import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\utils.py", line 8, in <module>
from .common import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\common.py", line 53, in <module>
import fixedpickle as pickle
ImportError: No module named fixedpickle
I solve this problem through uninstalling and reinstalling anaconda. Otherwise the installation of PyDsTools is very simple. It is not really installation at all, just unpack the zip folder and make sure it is in your python path (also add its parent directories to the python path). This may be done through Spyder IDE. Click tools> pythonpath
I received some assistance from the Sourceforge support thread for the PyDStool project here

PyDSTool on Windows 7 installation [duplicate]

I have downloaded PyDsTool for Windows. And I believe I have pointed python in the correct location. But I get the following error
from PyDSTool import *
Traceback (most recent call last):
File "<ipython-input-1-7b811358a37e>", line 1, in <module>
from PyDSTool import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\__init__.py", line 85, in <module>
from .Events import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\Events.py", line 13, in <module>
from .Variable import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\Variable.py", line 10, in <module>
from .utils import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\utils.py", line 8, in <module>
from .common import *
File "C:\Anaconda\lib\site-packages\pydstool-0.88.140328-py2.7.egg\PyDSTool\common.py", line 53, in <module>
import fixedpickle as pickle
ImportError: No module named fixedpickle
I solve this problem through uninstalling and reinstalling anaconda. Otherwise the installation of PyDsTools is very simple. It is not really installation at all, just unpack the zip folder and make sure it is in your python path (also add its parent directories to the python path). This may be done through Spyder IDE. Click tools> pythonpath
I received some assistance from the Sourceforge support thread for the PyDStool project here

Categories

Resources