我正在尝试使用Pyinstaller从我的.py脚本构建一个可执行文件。问题是它使用Python 2.7而不是Python 3.5构建它,因此我的可执行文件甚至不会运行。
cali@californiki-pc ~/Desktop $ pyinstaller --onefile Vocabulary.py
25 INFO: PyInstaller: 3.2.1
25 INFO: Python: 2.7.12
26 INFO: Platform: Linux-4.4.0-72-generic-x86_64-with-LinuxMint-18.1-serena
26 INFO: wrote /home/cali/Desktop/Vocabulary.spec
31 INFO: UPX is not available.
32 INFO: Extending PYTHONPATH with paths
['/home/cali/Desktop', '/home/cali/Desktop']
32 INFO: checking Analysis
33 INFO: Building Analysis because out00-Analysis.toc is non existent
33 INFO: Initializing module dependency graph...
34 INFO: Initializing module graph hooks...
139 INFO: running Analysis out00-Analysis.toc
160 INFO: Caching module hooks...
164 INFO: Analyzing /home/cali/Desktop/Vocabulary.py
246 INFO: Processing pre-safe import module hook _xmlplus
1991 INFO: Processing pre-find module path hook distutils
2209 INFO: Loading module hooks...
2209 INFO: Loading module hook "hook-distutils.py"...
2210 INFO: Loading module hook "hook-xml.py"...
2959 INFO: Loading module hook "hook-httplib.py"...
2960 INFO: Loading module hook "hook-encodings.py"...
3427 INFO: Looking for ctypes DLLs
3428 INFO: Analyzing run-time hooks ...
3435 INFO: Looking for dynamic libraries
3663 INFO: Looking for eggs
3663 INFO: Python library not in binary depedencies. Doing additional searching...
3707 INFO: Using Python library /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
3710 INFO: Warnings written to /home/cali/Desktop/build/Vocabulary/warnVocabulary.txt
3768 INFO: checking PYZ
3768 INFO: Building PYZ because out00-PYZ.toc is non existent
3768 INFO: Building PYZ (ZlibArchive) /home/cali/Desktop/build/Vocabulary/out00-PYZ.pyz
4122 INFO: Building PYZ (ZlibArchive) /home/cali/Desktop/build/Vocabulary/out00-PYZ.pyz completed successfully.
4172 INFO: checking PKG
4172 INFO: Building PKG because out00-PKG.toc is non existent
4172 INFO: Building PKG (CArchive) out00-PKG.pkg
7322 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
7336 INFO: Bootloader /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader/Linux-64bit/run
7336 INFO: checking EXE
7336 INFO: Building EXE because out00-EXE.toc is non existent
7336 INFO: Building EXE from out00-EXE.toc
7337 INFO: Appending archive to ELF section in EXE /home/cali/Desktop/dist/Vocabulary
7352 INFO: Building EXE from out00-EXE.toc completed successfully.
我如何克服这个问题?
@EDIT:
我试图像Claudio建议的那样使用pip3 install pyinstaller
安装Pyinstaller,但我得到了:
cali@californiki-pc ~/Desktop $ pip3 install pyinstaller
Collecting pyinstaller
Using cached PyInstaller-3.2.1.tar.bz2
Collecting setuptools (from pyinstaller)
Using cached setuptools-35.0.1-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools->pyinstaller)
Using cached appdirs-1.4.3-py2.py3-none-any.whl
Collecting packaging>=16.8 (from setuptools->pyinstaller)
Using cached packaging-16.8-py2.py3-none-any.whl
Collecting six>=1.6.0 (from setuptools->pyinstaller)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools->pyinstaller)
Using cached pyparsing-2.2.0-py2.py3-none-any.whl
Building wheels for collected packages: pyinstaller
Running setup.py bdist_wheel for pyinstaller ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-42qpk7iy/pyinstaller/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpmmn5007ppip-wheel- --python-tag cp35:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: invalid command 'bdist_wheel'
----------------------------------------
Failed building wheel for pyinstaller
Running setup.py clean for pyinstaller
Failed to build pyinstaller
Installing collected packages: appdirs, six, pyparsing, packaging, setuptools, pyinstaller
Running setup.py install for pyinstaller ... done
Successfully installed appdirs-1.4.3 packaging-16.8 pyinstaller-3.2.1 pyparsing-2.2.0 setuptools-35.0.1 six-1.10.0
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
答案 0 :(得分:0)
要解决您面临的问题,请使用以下方法安装PyInstaller:
pip3安装pyinstaller
然后注意你运行正确的(然后会有两个在不同的位置,一个在Python2.7模块的路径中,一个在Python3.5模块的路径中)
在我的机器上安装了PyInstaller for Python 3.5:
$ pip3 install pyinstaller
Collecting pyinstaller
Collecting setuptools (from pyinstaller)
Using cached setuptools-35.0.1-py2.py3-none-any.whl
Collecting six>=1.6.0 (from setuptools->pyinstaller)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools->pyinstaller)
Using cached appdirs-1.4.3-py2.py3-none-any.whl
Collecting packaging>=16.8 (from setuptools->pyinstaller)
Using cached packaging-16.8-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools->pyinstaller)
Using cached pyparsing-2.2.0-py2.py3-none-any.whl
Installing collected packages: six, appdirs, pyparsing, packaging, setuptools, pyinstaller
Successfully installed appdirs-1.4.3 packaging-16.8 pyinstaller-3.2.1 pyparsing-2.0.3 setuptools-20.7.0 six-1.10.0
安装没有问题...嗯......
尝试:
sudo -H pip3 install setuptools --upgrade
(参见更多here - 您并不是唯一遇到此问题的人)
答案 1 :(得分:0)
抱歉,我知道这不是一个答案,但我没有足够的声誉来评论:
检查此链接:
https://anaconda.org/acellera/pyinstaller
我用了大约10分钟为你找到一个合适的pyinstaller,但这是我能找到的最好的。对不起,如果我没有帮助
*我建议你使用anaconda。
答案 2 :(得分:0)
尝试:
py -3.5 -m PyInstaller Vocabulary.py --onefile
我认为它区分大小写
答案 3 :(得分:-1)
只需在pyinstaller中设置一个选项-upx-dir,指定python 3.5的路径。它也可以是虚拟环境。例如:
pyinstaller --upx-dir="$HOME/virtual-envs/<your-virtual-env>/lib/python3.5/site-packages/" <your-script>.py'