UPDATE: Actually, now I have checked, and PyInstaller is saying Invalid Syntax for EVERY script I have, even ones that I have previously packaged with PyInstaller without any issues. I uninstalled and reinstalled PyInstaller, but it's still having the same problem. Is PyInstaller not compatible with Python 3.5.1? That's the only thing I can think of that I might have updated between now and when everything was working fine
Original Question: I'm sure there is a really simple and stupid answer for what I'm doing wrong, because I can't seem to find any other cases of people having this problem.
I have a script I want to package into a standalone executable. In the past, I have used PyInstaller with minimal hassle. Py2exe and cx_freeze have never worked for me. I'm using Python version 3.5.1 and PyInstaller version 3.2, which I believe is the current version since I just uninstalled and reinstalled.
The command I am trying to use is so simple I feel like an idiot for having trouble.
pyinstaller --onefile myscript.py
File "<stdin>", line 1
pyinstaller --onefile myscript.py
SyntaxError: invalid syntax
It's giving a generic SyntaxError: invalid syntax even though that is the exact command straight from the PyInstaller docs.
To be sure, I also tried to include the entire path to my script in the command, added and took out quotation marks, and tried every variation I could think of but it gives me the same syntax error every time.
I'm pretty much a beginner, so any really advanced fixes will go over my head. But like I said, I assume it's something silly I've missed. Thanks in advance.
The syntax error is caused by your command itself, not by the code it calls.
This part is very indicative:
File "<stdin>", line 1
pyinstaller --onefile myscript.py
You actually tried to run that command in a Python shell.
But it is not Python code. You should run it in a usual shell (cli.exe, bash, …)
Run It In CMD
Why are you running it in python shell? It's a problem with python syntax because it is not even defined.
>>> pyinstaller --onefile myscript.py
And, by the way. You are not even importing the PyInstaller module.
Run this line on your CMD:
pyinstaller --onefile filename.py
Ensure your script doesn't has any syntax errors. If it's so, then pyinstaller will rethrow the exception and this could be one of the reason.
Related
I am using Python 3.7.9 with Pyinstaller 5.0.1
I am trying to freeze my code which uses pyshadow.
When I execute it from Pycharm it works fine.
When I execute the exe after I freezed the code, I get this error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\gauth\\AppData\\Local\\Temp\\_MEI233082\\pyshadow\\resources\\querySelector.js
This could be a common issue when your python code uses some specific module that needs some third files. In my case, it is about pyshadow missing a JS file.
So I add this file 'querySelector.js' in the freezing command:
pyinstaller --onefile -F --uac-admin --icon="icon_PhoneBot_256.ico" --clean --noconsole --add-data "querySelector.js;." main.py
But I still get the same error.
Does anyone have any idea how to fix this issue?
Thanks to rokm. I get his help from the git forum of the PyInstaller developer (full details here: https://github.com/pyinstaller/pyinstaller/discussions/6905). I publish his answer here in case someone has the same issue.
I had to add the parameter:
--collect-data pyshadow
So my final command is:
pyinstaller --onefile -F --uac-admin --icon="icon_PhoneBot_256.ico" --clean --noconsole --collect-data pyshadow main.py
ANd it works like a charm!
My code works fine when running from the terminal, but when I try to run it as an executable after compiling it, it gives me a No module named 'reportlab.graphics.barcode.code128' error. I tried uninstalling and installing it again but still outputs the same error. Any ideas?
I had the exact same issue. The code works perfectly fine. But when built and compiled, the executable doesn't work. The cause of the error is xhtml2pdf dynamically loading reportlab.graphics.barcode. The solution is to include the entire reportlab.graphics.barcode when building the executable.
In PyInstaller this can be done with:
pyinstaller --onefile --noconsole --collect-all reportlab.graphics.barcode script.py
In nuitka:
nuitka --onefile --windows-disable-console --include-package=reportlab.graphics.barcode --include-data-dir=path_to_reportlab\graphics\barcode=barcode script.py
A friend of mine asked me to write him a program, and I used pynput to handle some of the inputs and other features. When I convert the program an executable with pyinstaller, launcing the executable gives me this error: File "site-packages\pynput\keyboard\__init__.py", line 31, in <module> File "site-packages\pynput\_util\__init__.py", line 82, in backend ImportError [11492] Failed to execute script friend_project
I have tried using the pyinstaller command pyinstaller --onefile friend_project.py, and also using auto-py-to-exe to run it.
Using pyinstaller with other modules like pygame or pyopengl gives me no error, but this one module does.
Running the script by it self with the python inturpeter works fine, but I would perfer to have it be an exe so I can give it to him with out him needing python to run it.
Please fall back to 1.6.8 version of pynput.
pip install pynput==1.6.8
If you are running Windows you need to add these parameters to the command line (for the first time, after that they will be included in the generated spec file).
--hidden-import "pynput.keyboard._win32" --hidden-import "pynput.mouse._win32"
For Linux, use:
--hidden-import "pynput.keyboard._xorg" --hidden-import "pynput.mouse._xorg"
More information can be found in this Github issue.
I'm a beginner of Python and I want to run a python3 script in PyCharm Python Console, but it raise an error below:
>>> /Users/mymac/Documents/Python/test.py
File "<input>", line1
/Users/mymac/Documents/Python/test.py
^
SyntaxError: invalid syntax
I don't know what's wrong the file path is, how can I solve the problem?
use execfile('/Users/mymac/Documents/Python/test.py'). You are trying to run a python file like an executable. On top of that you are doing it in python interpreter.
Use python's execfile routine to call a file from interpreter or use python test.py to run it from the terminal.
I recognized that the answer I accepted ahead wasn't a perfect method, cause function execfile has been deleted in Python3, the alternative method is using open like:
>>> with open ('/Users/mymac/Documents/Python/test.py', 'r') as f:
... exec(f.read())
...
Still thanks for guys who helped me!
This could be several things. Have you set your environmental correctly? You can test this by cmd: python it should return Python 3.6.4 if that is your current version. If not then head over to tutorialsPoint for how to correctly set up your path.
If that is correctly configured, then have you selected an interpreter in PyCharm. If not, File --> Settings --> Project: Network --> Project Interpreter. Select your python installation path.
Another thing to note is that I suspect you mean to use the terminal instead of the python console.
Then in PyCharms terminal section, python test.py.
I know that questions have already been raised on this topic, but I believe that all decisions were strictly individual. The essence of the problem:
There is a calculator.py script and a kalkulator.py These files are in the same directory, the calculator file is executable, this is the file that I convert into an EXE using PyInstaller. Inside the file, I import several PyQt5 libraries, and the second file is Python: from kalkulator import *
The second file kalkulator.py contains the GUI of the program created with QtDesigner
When i run the command pyinstaller --onefile --debug calculator.py everything goes fine.
But when I run the EXE program file in debug mode, I see the following error:
The photo shows that the following error occurs.
"DLL Load Failed: The specified procedure could not be found."
I can assume that the problem is that when assembling, PyInstaller does not see the file kalkulator.py it contains a graphical interface.
What can you say about this problem, how do you think you can solve it?
I use:
Python 3.5
PyQt5
PyInstaller 3.3.1
I managed to solve my problem! I changed the version of Python 3.5.0 to 3.6.0, and also reinstalled PyQt5.