Permission Error When Trying to Use PyInstaller Permission Error When Trying to Use PyInstaller python-3.x python-3.x

Permission Error When Trying to Use PyInstaller


Trick is to make a new directory outside of the one you are building, and then make the build reference the main.py of the Kivy app like in the code below. This fixes permission errors, even from a regular CMD.

PS C:\Users\theguy\Documents\Python\myapp-build> python -m PyInstaller --name "MyApp" "C:\Users\theguy\Documents\Python\myapp\main.py"


I ran across this same error and found that when I built it in PowerShell with admin rights it worked.


I met the same problem!

I figure out it is my antivirus software(Bitdefender) thinks the write out .exe is dangerous, so it block the action.

After I add my work folder to antivirus software Exclusions then reboot computer, it works.

Update:

You need to "Code Signing" your .exe file to make antivirus software think it is less dangerous.

In Windows:

Using OpenSSL to create self-signing, then using Win10 SDK signtool.exe

OpenSSL Command Example:

openssl genpkey -out privkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:4096openssl req -new -x509 -key privkey.pem -out cert.pem -days 3650openssl pkcs12 -inkey privkey.pem -in cert.pem -export -out privkey_cert.pfx -passout pass:[PASSWORD]

signtool Command Example:

signtool sign /debug /f privkey_cert.pfx /p [PASSWORD] [EXECUTE_FILE.exe]

Update 2:

Avoid using command with .spec file

$ pyinstaller FILE.spec

Using Auto PY to EXE to instead of .spec

I don't know WHAT happen with .spec file, but it produces single executable file more problems than .py file do

Update 3:

Make sure every time to clear auto-py-to-exe "Building directory" before executing auto-py-to-exe, you may execute ones to get temp folder path.

for example:

Output

Running auto-py-to-exe v2.9.0Building directory: C:\Users\John\AppData\Local\Temp\tmpevxvuugzProvided command: pyinstaller --noconfirm --onefile --windowed ...

Update 4:

I reinstall entire windows os, then run the same thing without clear "Building directory" it turn out is fine! I rethink about it is a virus to infect "Building directory" make all this problem.