Python 配置 Pycharm 以运行 Pyinstaller
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33906539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Configuring Pycharm to run Pyinstaller
提问by gerosalesc
Yes I want to create a run configuration in PyCharm to run Pyinstaller and get my executable. According to the Pyinstaller documentationyou should be able to locate an python script called pyinstaller-folder/pyinstaller.py
after the installation, but it wasn't there. Then I look carefully and found this other one named pyinstaller-folder/__main__.py
which should be the same <--(me wild guessing), so I set up my running configuration like this:
是的,我想在 PyCharm 中创建一个运行配置来运行 Pyinstaller 并获取我的可执行文件。根据Pyinstaller 文档,您应该能够找到pyinstaller-folder/pyinstaller.py
安装后调用的 python 脚本,但它不存在。然后我仔细查看,发现另一个名字pyinstaller-folder/__main__.py
应该是相同的<--(我胡乱猜测),所以我设置了我的运行配置,如下所示:
After running it, is giving me this error:
运行后,给我这个错误:
/usr/local/Cellar/python3/3.4.3/bin/python3.4 /usr/local/lib/python3.4/sit
e-packages/PyInstaller/__main__.py --onefile --nowindow --osx-bundle-identifier=jg.optimizer -F --name=genoptimizer optimizer/manage.py
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/PyInstaller/__main__.py", line 26, in <module>
from . import __version__
SystemError: Parent module '' not loaded, cannot perform relative import
Process finished with exit code 1
It seems to require a parent module to run but, how would that look like?
它似乎需要一个父模块才能运行,但是,那会是什么样子?
采纳答案by codewarrior
The PyInstaller package is a runnable module and can be run using python -m PyInstaller
. To configure it as a run target in PyCharm, leave the "Script" field blank, write -m PyInstaller
in the "Interpreter Options" field, and put the PyInstaller parameters into the "Script Parameters" field.
PyInstaller 包是一个可运行的模块,可以使用python -m PyInstaller
. 要将其配置为 PyCharm 中的运行目标,请将“脚本”字段留空,-m PyInstaller
在“解释器选项”字段中写入,并将 PyInstaller 参数放入“脚本参数”字段。
For example:
例如:
PyCharm will complain that the "Script" field is empty, but it will let you run the configuration anyway.
PyCharm 会抱怨“脚本”字段为空,但无论如何它都会让您运行配置。
回答by Mumblepins
For those of us on Windows with Anaconda trying to figure this out, I found it easiest to just set up a Bash Configuration (I believe you need the BashSupport plugin for this), and set:
对于我们这些在 Windows 上使用 Anaconda 试图解决这个问题的人来说,我发现最简单的方法是设置 Bash 配置(我相信您需要为此使用 BashSupport 插件),然后设置:
- Script:
pyinstaller
(assuming pyinstaller is in your path, if not, the full path) - Interpreter path:
C:\Windows\system32\cmd.exe
(yes, a bash configuration can just use the standard command program) - Interpreter options:
/C
- Program arguments:
script_name.py
(along with any other pyinstaller arguments) - Working Directory:
C:\Path\To\Script
- 脚本:(
pyinstaller
假设pyinstaller在您的路径中,如果没有,则为完整路径) - 解释器路径:(
C:\Windows\system32\cmd.exe
是的,一个bash配置只能使用标准命令程序) - 口译选项:
/C
- 程序参数:(
script_name.py
以及任何其他 pyinstaller 参数) - 工作目录:
C:\Path\To\Script
回答by aerobiomat
After more than two years, perhaps there is a better option.
两年多之后,或许还有更好的选择。
In the PyCharm menu go to File-> Settings.
In the Settings dialog find Tools-> External toolsand use the green + to add a new external tool.
在 PyCharm 菜单中转到File-> Settings。
在设置对话框中找到工具->外部工具并使用绿色 + 添加一个新的外部工具。
For example:
例如:
Then, the IDE will allow you to run it on any python script. Right click on the file and the context menu will show External tools-> PyInstaller.
然后,IDE 将允许您在任何 python 脚本上运行它。右键单击该文件,上下文菜单将显示External tools-> PyInstaller。
回答by debugging XD
So as Pycharm has newly updates, my case was a bit different as I installed pyinstaller
from the interpreter settings as the following picture shows:
所以由于 Pycharm 有新的更新,我的情况有点不同,因为我是pyinstaller
从解释器设置安装的,如下图所示:
For Linux Users:
对于 Linux 用户:
You could install it in both Python 2.7
or Python 3.7+
. Make sure to get the path of where pyinstaller
was stored.Then in the Settings option, try to find Tools -> External tools and add a new external tool as the following picture shows:
您可以在两者Python 2.7
或Python 3.7+
. 确保获取存储位置的路径。pyinstaller
然后在设置选项中,尝试找到工具 -> 外部工具并添加一个新的外部工具,如下图所示:
For Windows users:
对于 Windows 用户:
If you are using Pycharm or any virtual environment. Unfortunatelly Pycharm creates its local vertual environment in venv
path once you indicate the interpreter
. So, you should set the external tool (pyinstaller) to the real path of your python 3.7 .exe as the picture shows
如果您使用的是 Pycharm 或任何虚拟环境。不幸的是,venv
一旦您指定interpreter
. 因此,您应该将外部工具(pyinstaller)设置为您的python 3.7 .exe 的真实路径,如图所示
回答by Mehran Jalili
Install pyinstaller in pycharm, then open the pycharm terminal and write python -m PyInstaller
.
在pycharm中安装pyinstaller,然后打开pycharm终端,写入python -m PyInstaller
.
回答by John Jairo Sanabria Sarmiento
output for pyinstaller on pycharm windows 8
pycharm windows 8 上 pyinstaller 的输出
argumento fails
--- V
-y -F V
-y -F --onefile V
-y -F --onefile -c $FileName$ F (default path)
-y -F --onefile -w $FileName$ F (default path, no console neither cmd)
-y -F --onefile -c $FileName$ --distpath $FileDir$ F (path as project)
-y -F --onefile -c $FileName$ --distpath $FileRelativePath$ V
best selection -> line four or six
回答by Dionys
The run command has changed a bit since the accepted answer. You can now select a module to launch rather than editing the interpreter options.
自从接受的答案以来,运行命令发生了一些变化。您现在可以选择要启动的模块而不是编辑解释器选项。
As of writing this answer, here how it looks like:
在撰写此答案时,它的外观如下:
Notes:
笔记:
- This solution requires to install
PyInstaller
in the virtual environment of the project. - I am using PyCharm pro 2020.1
- Old solution should still work
- Using external tool is still a possibility. Which solution you choose is a matter of personal preference.
- 该解决方案需要安装
PyInstaller
在项目的虚拟环境中。 - 我正在使用 PyCharm pro 2020.1
- 旧的解决方案应该仍然有效
- 使用外部工具仍然是可能的。您选择哪种解决方案取决于个人喜好。