PyInstaller - Program returns -1 in another computer - python

I am using PyInstaller to compile my program to an .exe in Windows,
I use the normal line: pyinstaller file.py --onefile
And all looks like working, while executing PyInstaller says about a WARNING but still "Succesfull finished".
So then i execute my program file.exe and it works perfectly.
The surprise comes when i go to another computer and try to run it...
It start running but when it achieves a point it returns:
Traceback: TypeError: 'NoneType' object has no attribute 'getitem' files returned -1
Warnings of compilations are:
missing module named 'Carbon.File'.FSGetResourceForkName - imported by 'Carbon.File', plistlib
missing module named 'Carbon.File'.FSRef - imported by 'Carbon.File', plistlib
...170 more...
Well, so now comes the question and sorry about the "long" post:
I am not using Carbon,math.cos,etc,etc (From Warning files) in my program I even dont know what Carbon is, it is "imported by ...", how can I do this to dont be imported so it will work in all computers.
If my program works in my computer but not in other I guess I am leaving out something to import?
I have seek for answer and ofc there are but what I have found are really specific: Example: pyInstaller: Import Error What to do when your imports are missing 170 modules?
Thanks!
Edit:
Full Traceback:
Code:
def check_actived (connection):
sql_query = """SELECT enabled FROM login """
connection.execute(sql_query)
result = connection.fetchone()
return result[0]

Related

Blessed / Curses controls don't work with Pyinstaller. Missing vtwin10

I have a very simple Python program that uses 'Blessed'. It works fine with the Win10 Python interpreter, but reports an error when packaged with Pyinstaller, and terminal control codes are ignored. Here's the code:
from blessed import Terminal
t = Terminal()
print(t.bright_green('Hello world'))
The string 'Hello world' is supposed to display on the console in bright green. Pyinstaller completes with no errors, and when I run the .exe, I get the message:
terminal.py:222: UserWarning: Failed to setupterm(kind='vtwin10'): Could not find terminal vtwin10
and then 'Hello world' is displayed in default terminal color.
It looks like Pyinstaller isn't including something in the build that the interpreter finds without issue. I found a vtwin10.py file in my Anaconda3 installation folder at:
C:\Anaconda3\Lib\site-packages\jinxed\terminfo
I looked at the referenced error in the blessed library's terminal.py file. Here's the code:
try:
curses.setupterm(self._kind, self._init_descriptor)
except curses.error as err:
warnings.warn('Failed to setupterm(kind={0!r}): {1}'
.format(self._kind, err))
So it looks like self._kind is being set to 'vtwin10'. There is a conditional import in terminal.py that looks like this:
if platform.system() == 'Windows':
import jinxed as curses # pylint: disable=import-error
HAS_TTY = True
(I get the humor.) It looks like the jinxed package is being imported explicitly in the code, and replaces the curses package. But somehow the vtwin10 definition is missing.
I found setupterm() in jinxed and dug deeper to find where that error message is coming from. It's in this code:
try:
self.terminfo = importlib.import_module('jinxed.terminfo.%s' % term.replace('-', '_'))
except ImportError:
raise error('Could not find terminal %s' % term)
This is where I get stuck. It looks like this code is unable to find the vtwin10.py file in the jinxed library. Does anyone know how to force Pyinstaller to include the vtwin10 terminal definition for curses? I'm guessing this is the problem.
Many thanks.
For now you will only need to specify jinxed.terminfo.vtwin10 and jinxed.terminfo.ansicon on Windows, but if you want it to be more dynamic, pyinstaller spec files are executable Python, so you can just dynamically look up any terminfo modules.
import pkgutil
import jinxed.terminfo
hiddenimports = [mod.name for mod in pkgutil.iter_modules(jinxed.terminfo.__path__, 'jinxed.terminfo.')
Finally figured this out. In the jinxed library, the code line:
importlib.import_module('jinxed.terminfo.%s' % term.replace('-', '_'))
dynamically loads a library module. Pyinstaller can't package dynamically imported modules. So to fix this, I need to specify the module using the --hidden-import option. The syntax is as follows:
pyinstaller --hidden-import=jinxed.terminfo.vtwin10 --onefile test.py
Program works just like in the interpreter. It works, but I'm concerned this breaks any platform independence jinxed was supposed to have. I can force import the vtwin10.py module, and it will work on win10 platforms. But the way jinxed is written, it figures out the windows platform and then dynamically loads the required terminfo module. There are a number of them in the jinxed.terminfo directory. Wildcards for --hidden-import don't work, so the only option is to use --hidden-import for every file in the jinxed.terminfo folder.

How to fix invaild module when using pyinstaller

I am trying to compile my python file to executable file using pyinstaller.
I put all the dependent packages and the source python file in one folder.
And I tried pyinstaller --onefile [my python file name].py
It succeeded to build the exe file. However, the exe file fails to run and I checked the warn-[my python script name].txt, there is one invalid module from which I imported the class to my python code.
In my code, I also imported another module, it was working.
from autobench.inst import power, func_gen
from autobench.i2c.aa_i2c import AAreadWrite
invalid module named autobench.i2c.aa_i2c - imported by C:\Users\jgou\Desktop\test\AP711T_OTP_Program.py (top-level)
Autobench and inst and i2c are folders. Power, func_gen and aa_i2c are python files (.py), AAreadWrite is class in aa_i2c file.
Please suggest what is wrong and how to fix this one. Thanks.

ImportError when execute script from command line

When executing script from command line, I got the following error
ImportError: No module named SubPackage3.MyClass
My package is structured as
TopLevelPackage
..SubPackage1
..SubPackage2
..SubPackage3
..__init_.py
..README.md
python (/usr/bin/python)
From other posts it seems that the problem is that the system does not recognize the path to SubPackage3. I have a separate __init_.py in each of the SubPackage, and print(sys.path) gave me
/home/shaunz/workspace/TopLevelPackage/SubPackage1
/home/shaunz/workspace/TopLevelPackage
/usr/lib/python2.7
....
Notice that only Package 1 is in the list of paths recognized. Any idea why this may be the case? And how do I change it?
I'm trying to run a module in SubPackage2. I'm using Eclipse.
Thanks

Pyinstaller - ImportError: No module named mtrand in Linux

I am trying to build an executable using pyinstaller and ran in to trouble with certain modules not being/getting imported. Here is the smallest piece of code for which gives various errors. I was able to fix first few errors but am stuck on the current one.
import numpy as np
def test_module():
print "Test Starts"
a=np.array([(1,4),(2,6),(3,9),(4,1)])
print np.size(a)
print np.shape(a)
print "Test Ends"
test_module()
With the default spec file that was generated, I was getting the error “import multiarray failed”.
By adding the numpy path in pathex under Analysis in .spec file, this error got fixed.
Now I am getting an error “ImportError: No module named mtrand”
But I have “random.mtrand.so” and “numpy.random.mtrand.so” in the dist folder.
I also tried copying the “mtrand.so” from “/numpy/ramdom/mtrand.so”
I have also checked by giving ‘numpy’ , ‘numpy.random’ or ‘numpy.random.mtrand’ in hidden imports as well.
I am still not able to fix this issue.

Python weave blitz DLL error

I'm trying to use weave.blitz to speed up some code and I keep getting the following DLL error. If I run a simple code, e.g.
from scipy import * # or from NumPy import *
a = ones((512,512),'Float64')
b = ones((512,512),'Float64')
# now average
a[1:-1,1:-1] = (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1] \
+ b[1:-1,2:] + b[1:-1,:-2]) / 5.
from scipy import weave
expr = "a[1:-1,1:-1] = (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]" \
"+ b[1:-1,2:] + b[1:-1,:-2]) / 5."
weave.blitz(expr)
I get the following error:
Traceback (most recent call last):
File "C:\Users\Thijs\wtest.py", line 19, in <module>
weave.blitz(expr)
File "C:\Python27\lib\site-packages\scipy\weave\blitz_tools.py", line 65, in blitz
**kw)
File "C:\Python27\lib\site-packages\scipy\weave\inline_tools.py", line 488, in compile_function
exec 'import ' + module_name
File "<string>", line 1, in <module>
ImportError: DLL load failed: Invalid access to memory location.
I'm using the latest Pythonxy and I usually write my code in Spyder; not sure if that has anything to do with it. Any ideas?
I'm also using python 2.7 64bit/weave.inline under windows 7 and just met the same issue as you described here. I searched the whole internet but this post seems like the only related one and i got no answer.
I traced the weave.inline function and try to load the pyd from compiled binary. Then i found that the loading is successful if i try
python -c "import sys; sys.path.insert(0, 'C:\\Users\\zliu\\AppData\\Local\\Temp\\zliu\\python27_compiled'); import sc_d4c0ee9cff8db6a9b5fc8352299944210;" where the module name being some hash value apparently.
However if I start python interactive then input the exact same statements in the interactive mode, it just shows
ImportError: DLL load failed: Invalid access to memory location.
So next i tried to compare the output of python -c -v "..." and python -v, finally i was able to locate the devil different line:
import string
I have no idea why python -c and python interactive are different in this or why without this module the import show such an ambiguous message. But putting it at the beginning of the script just works for me.
I am sorry for posting to such an old thread, and I do not offer an working solution or exaplantion of the problem, it is just a comment. ImportError: DLL load failed: Invalid access to memory location. I encountered the same error when trying to make my own extension of Python programmed in C. Platform Windows 32-bit.
It was a real pain because this error appeared randomly in interactive as well as in non-interactive mode in all Python environments (Spyder, Notebook, plain console...). I compiled my code using MinGW and Python's distutils (command python setup.py install). The compilation gave no warnings or errors and produced pyd file to the correct directory. But when trying to import this module import example pro my Python code it irregularly crashed (usually only one out of five attempts to import the module succeeded).
Strange was that on another computer it worked just fine... Well, I finally found a workaround - I downloaded a newer version of MinGW (before I had used the version that comes packed in Qt SDK distribution) and compiled the module again. Then it worked with no more crashes. However I did not find any systematic solution or explanation. So I might have something to do with the compiler (maybe absence of its DLLs? I do not know exactly) that was used to generate the pyd file.

Categories

Resources