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.
Related
import winshell
r = list(winshell.recycle_bin())
for index, value in enumerate(r):
print(index, value.original_filename())
This is the simple script I wrote, but when I try running it (or antyhing else that uses winshell) I get this error:
ModuleNotFoundError: No module named 'win32'
And when I try running pip install win32 I get another error:
ERROR: Could not find a version that satisfies the requirement win32 (from versions: none)
ERROR: No matching distribution found for win32
So now I'm even more confused. Why does winshell need a different module? That module doesn't even exist. Is it fine if I use some different module than the non-existent win32? If so which one? What am I supposed to do now?
First, you have to execute the script inside the Scripts directory, the pywin32_postinstall.py. Let’s say your Python directory is C:\python3, just follow the code below.
cd C:\python3
python Scripts/pywin32_postinstall.py -install
After that, the installation will drop the DLL files under the C:\Windows\System32. You need to move those two files ( pythoncom310.dll and pywintypes310.dll) to C:\python3\Lib\site-packages\win32 directory.
After that, you need to edit the python310._pth that you can find inside the Python installation folder. Then make the following changes:
Lib/site-packages
Lib/site-packages/win32
Lib/site-packages/win32/lib
Lib/site-packages/pythonwin
python310.zip
#Uncomment to run site.main() automatically
#import site
Save and try running your code again.
Troubleshoot
If you still get an error saying “ImportError: DLL load failed while importing win32api: The specified module could not be found.”, make sure you have copied the two dll files to Lib\site-packages\win32 directory.
PythonWin32Api
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.
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]
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
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.