当尝试使用PyInstaller部署Kivy App时,即使在使用Administrator CMD时,我也收到“拒绝权限”错误。该文件夹为每个用户提供所有打开的编辑选项。 Python具有防火墙访问权限。该如何解决?
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'
答案 0 :(得分:1)
技巧是在要构建的目录之外创建一个新目录,然后像下面的代码中那样使该构建引用Kivy应用程序的main.py。这样可以修复权限错误,甚至是来自常规CMD的错误。
PS C:\Users\theguy\Documents\Python\myapp-build> python -m PyInstaller --name "MyApp" "C:\Users\theguy\Documents\Python\myapp\main.py"
答案 1 :(得分:0)
我遇到了同样的错误,发现当我使用管理员权限在 PowerShell 中构建它时,它可以工作。
答案 2 :(得分:0)
我的环境是pycharm使用venv环境,最后打开权限总是有问题。我把pycharm的python环境改成系统环境,运行正常。
答案 3 :(得分:-1)
错误提示“INFO: UPX is not available”,需要导入UPX.exe,这个问题就解决了。
答案 4 :(得分:-1)
我遇到了同样的问题!
我发现这是我的防病毒软件(Bitdefender)认为写出的 .exe 很危险,所以它阻止了操作。
将我的工作文件夹添加到防病毒软件排除然后重新启动计算机后,它可以工作。
更新:
您需要对您的 .exe 文件进行“代码签名”,以使防病毒软件认为它不那么危险。
在 Windows 中:
使用OpenSSL创建自签名,然后使用Win10 SDK signtool.exe
OpenSSL 命令示例:
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 命令示例:
signtool sign /debug /f privkey_cert.pfx /p [PASSWORD] [EXECUTE_FILE.exe]
更新 2:
避免在 .spec 文件中使用命令
$ pyinstaller FILE.spec
使用 Auto PY to EXE 代替 .spec
我不知道 .spec 文件发生了什么,但它产生的单个可执行文件比 .py 文件产生的问题更多
更新 3:
确保每次在执行 auto-py-to-exe 之前清除 auto-py-to-exe “Building directory”,您可以执行那些来获取临时文件夹路径。
例如:
输出
Running auto-py-to-exe v2.9.0
Building directory: C:\Users\John\AppData\Local\Temp\tmpevxvuugz
Provided command: pyinstaller --noconfirm --onefile --windowed ...