Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission Error When Trying to Use PyInstaller

When trying to deploy a Kivy App using PyInstaller, I am getting Permission Denied errors even when using and Administrator CMD. The folder has all open editing options for every user. Python has firewall access. How to fix this?

PS C:\Users\theguy\Documents\Python\myapp-build> python -m PyInstaller --name "MyApp" "./"
422 INFO: PyInstaller: 3.3.1
422 INFO: Python: 3.6.5
424 INFO: Platform: Windows-10-10.0.17134-SP0
425 INFO: wrote C:\Users\theguy\Documents\Python\myapp-build\myapp.spec
426 INFO: UPX is not available.
427 INFO: Extending PYTHONPATH with paths
['C:\\Users\\theguy\\Documents\\Python',
 'C:\\Users\\theguy\\Documents\\Python\\myapp-build']
428 INFO: checking Analysis
428 INFO: Building Analysis because out00-Analysis.toc is non existent
429 INFO: Initializing module dependency graph...
432 INFO: Initializing module graph hooks...
434 INFO: Analyzing base_library.zip ...
3859 INFO: running Analysis out00-Analysis.toc
3861 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Anaconda3\python.exe
4398 INFO: Caching module hooks...
4402 INFO: Analyzing C:\Users\btdav\Documents\Python\
Traceback (most recent call last):
  File "C:\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 101, in <module>
    run()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 94, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build
    exec(text, spec_namespace)
  File "<string>", line 16, in <module>
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 213, in __init__
    self.__postinit__()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__
    self.assemble()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 415, in assemble
    priority_scripts.append(self.graph.run_script(script))
  File "C:\Anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 201, in run_script
    self._top_script_node = super(PyiModuleGraph, self).run_script(pathname)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1334, in run_script
    with open(pathname, 'rb') as fp:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\theguy\\Documents\\Python\\myapp-build'
like image 501
The Guy Avatar asked Aug 10 '18 02:08

The Guy


Video Answer


2 Answers

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"
like image 55
The Guy Avatar answered Oct 04 '22 11:10

The Guy


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:4096
openssl req -new -x509 -key privkey.pem -out cert.pem -days 3650
openssl 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.0
Building directory: C:\Users\John\AppData\Local\Temp\tmpevxvuugz
Provided 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.

like image 21
林奕忠 Avatar answered Oct 04 '22 10:10

林奕忠