Converting a python 3.8 file to .exe

杀马特。学长 韩版系。学妹 提交于 2020-12-31 05:02:30

问题


I've been trying to do so for a while. I followed a tutorial which said you should install pyinstaller first. So, I installed it. Then it said you should write pyinstaller --onefile -w file_name.py in cmd. I had an issue with that as well (there was an error). So, I installed another version of pyinstaller. I wrote the same thing, but no .exe file was created, only a new folder named "pycache" with a new .pyc file inside (I suppose it's a version of the file I wanted to turn into .exe). Then I tried installing cx freeze but pip won't install it.

I don't know what's the best way, maybe one of you have already tried doing this?

edit - here is what I wrote in cmd and what it said:

K:\>pyinstaller --onefile -w K:\geut_project\client_nuovo.py

74 INFO: PyInstaller: 4.0.dev0+9dd34bdfba

74 INFO: Python: 3.8.0

74 INFO: Platform: Windows-10-10.0.17134-SP0

250 INFO: wrote K:\client_nuovo.spec

252 INFO: UPX is not available.

261 INFO: Extending PYTHONPATH with paths

['K:\\geut_project', 'K:\\']

261 INFO: checking Analysis

312 INFO: checking PYZ

364 INFO: checking PKG

380 INFO: Building because K:\build\client_nuovo\client_nuovo.exe.manifest changed

380 INFO: Building PKG (CArchive) PKG-00.pkg

3881 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.

3897 INFO: Bootloader c:\users\user1\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe

3898 INFO: checking EXE

3918 INFO: Rebuilding EXE-00.toc because pkg is more recent

3918 INFO: Building EXE from EXE-00.toc

3929 INFO: Appending archive to EXE K:\dist\client_nuovo.exe

6885 INFO: Building EXE from EXE-00.toc completed successfully.

K:\>

As I said I expected it to create an executable file but it didn't (as far as I know). It only created a folder named __ pycache__ and inside a file named client_nuovo.cpython-38.pyc (the original file's name is client_nuovo).


回答1:


According to this issue, PyInstaller doesn't support python 3.8 yet: https://github.com/pyinstaller/pyinstaller/issues/4311




回答2:


I fought with this problem for roughly 3 weeks before stumbling upon a simple solution that works and should work regardless of system. I am running mac and was trying my hardest to make a pygame file with png and font dependencies run as an exec file. Heres what worked, make a virtual environment using python3.6 in terminal. The commands are simple.

#If you don't have virtual environment installed, do pip install virtualenv

Then the following line for line.

virtualenv venv -p python3.6

source venv/bin/activate

pip install pyinstaller

pyinstaller -F myfile.py

If you have dependencies like png's or whatever, you will need to modify the myfile.spec file that pyinstaller just created in your working directory. If you don't have any dependency files, your exe is ready to go and you can leave here. The exe file is in a folder called 'dist'

Open the spec file, and go to the region called datas[]. you will need to add in the dependencies like this. The assets folder is just where i decided to keep my assets, if you just have your assets in the same folder as your python file follow the second line I put with datas.

datas = [('assets/picture.png', 'assets'), ('assets/font.ttf', 'assets')]

#if the dependancies are in the same folder as the pyfile:
datas = [('picture.png', '.'), ('font.ttf', '.')]

save the spec file and then go back to terminal and enter the following:

pyinstaller myfile.spec

it might ask you about removing some data from the initial folder which will end with something like, "Remove this data[y/N]?" enter y

now you can get take the exe file from a folder called 'dist' and you can trash the folders 'pycache', 'dist' 'build' and the spec file. The exe should now work just by double clicking on it.



来源:https://stackoverflow.com/questions/59134747/converting-a-python-3-8-file-to-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!