I am trying to convert python code to a windows .exe using cx_freeze. When I run the setup.py using the command line it runs as usual and then just returns invalid syntax. The program uses the tkinter module as well as sympy and I believe it is the latter causing the problem. Any solutions will be much appreciated. Below is the last part of the process before it stops.
deferredImports, namespace = namespace)
File "C:\Python33\lib\site-packages\cx_Freeze\finder.py", line 338, in _Intern
alImportModule
parentModule, namespace)
File "C:\Python33\lib\site-packages\cx_Freeze\finder.py", line 366, in _LoadMo
dule
module.code = compile(codeString, path, "exec")
File "C:\Python33\lib\site-packages\sympy\mpmath\libmp\exec_py2.py", line 2
exec string in globals, locals
^
SyntaxError: invalid syntax
The compatibility for exec in SymPy (actually mpmath, which is included with SymPy) uses a file that is only run in Python 2 that is invalid syntax in Python 3 and a file that is only run in Python 3 that is invalid syntax in Python 2. You can safely ignore the one on the other. If cx_freeze refuses to skip this file, you can safely delete it.
Related
This script was running ok before I upgraded from 15.1 to 15.2 (LInux LEAP)
import pixellib
import time
from pixellib.instance import instance_segmentation
segment_image=instance_segmentation()
segment_image.load_model("mask_rcnn_coco.h5")
start = time.time()
segment_image.segmentImage("thisone.png",output_image_name="thisone_ryzen.png",show_bboxes = True)
end = time.time()
print(f"Inference Time: {end-start:.2f}seconds")
Now I have these errors:
sirius:/cours/journalisme/ia/ryzen7 # ./rigolade.py
./rigolade.py: line 4: from: command not found
./rigolade.py: line 6: syntax error near unexpected token `('
./rigolade.py: line 6: `segment_image=instance_segmentation()'
It used to run when you did python3 ./rigolade.py, but now you're doing ./rigolade.py. By doing that, and not including a shebang line for Python, it's trying to execute the script as shell commands. Add a shebang line like:
#!/usr/bin/env python3
to the very top of the file (very first line) and it should work. Or just run it using python3 (or python, environment dependent) explicitly like you used to.
The reason the error doesn't occur until the third line is because many Linux distros actually ship with a tool named import (often a screenshot snipping tool); you might want to delete the pixellib and time files it just left in your working directory. But from isn't a recognized command, and the parentheses don't match your shell's syntax rules, so it starts erroring out at that point.
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 understand this question has been asked multiple times and answered in different forums but it looks like there are variants of the issue and mine is probably, slightly different.
Let me explain. I am trying to call a octave function which I had written for plotting and I don't want to re-write it again python. Therefore I did the following:-
1. install the oct2py
2. setup the OCTAVE_EXECUTABLE= c:\Octave\Octave-4.2.1\bin\octave-gui.exe
3. did the following in the code:-
#importing oct2py
from oct2py import octave as oc
oc.addpath("C:\\personal\\learning\\octave-lib") #containing my octave .m files
#Now I am trying to call a plot function written in octave called displayData.m
oc.displayData(X) # where X is a numpy matrix for plotting
However on executing call to the method gives no errors - but it does not do anything. I see a windows shell prompt opening & closing but nothing else.
I have also tried to replace octave-gui-4.2.1.exe with octave-cli-4.2.1.exe following the suggesting from some sites but I was getting errors that bulk of the windows dll required were not found.
I started with the advice from the oct2py site asking me to just add the path to the folder containing octave.exe ( note that this folder contains all the octave executable) , but that resulted in windows permission errors. There should not be any reason for this error since I am the only user on my windows laptop and have administrative privileges. I am getting the following errors:-
File "mcclassifier.py", line 21, in <module>
from oct2py import octave as oc
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\__init__.py", line
38, in <module>
octave = Oct2Py()
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\core.py", line 73,
in __init__self.restart()
File "C:\Users\Sam\Anaconda3\lib\site-packages\oct2py\core.py", line 508, in restart logger=self.logger)
File "C:\Users\Sam\Anaconda3\lib\site-packages\octave_kernel\kernel.py",
line 144, in __init__
self.repl = self._create_repl()
File "C:\Users\Sam\Anaconda3\lib\site-packages\octave_kernel\kernel.py",
line 338, in _create_repl
version = subprocess.check_output(version_cmd).decode('utf-8')
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\Sam\Anaconda3\lib\subprocess.py", line 990, in
_execute_child startupinfo)
PermissionError: [WinError 5] Access is denied
I tried to run it from Spyder IDE and also from the command line. Both have the identical behavior. Its been frustrating , so any suggestion to get me past this issue will be a big help !!
ADDITIONAL INFORMATION:-
Probably I was not very clear above, but what I am trying to do is to execute a plotting function which i had implemented in octave, & is working.
I made some changes to my python code to see if I can instantiate the Oct2Py class and then call feval function. I commented the previous lines of code above and added the following:-
octave=oct2py.Oct2Py()
octave.feval('C:\\personal\\learning\\octave-lib\displayData',Xmat,timeout=80)
I can see from the windows taskbar that octave-gui.exe being invoked and is seen as running in the background. But it is still not plotting and there is no error.
How do I make it run as foreground process and render the plot. What I want to do is similar to what is shown in the oct2py demo example at:-
http://blink1073.github.io/oct2py/source/demo.html.
As you can see that oc.plot([1,2,3],...) renders the plot.
I will greatly appreciate any help here ?
I am looking at using setup.py to automatically generate python 3 code from python 2 sources using the 'use_2to3' attribute. My setup.py script includes the following statement:
VERSION = None
with file('version','rt') as FF:
VERSION = FF.read().lstrip().rstrip()
print("VERSION %s" % (VERSION) )
When I type 'python3 setup.py build' I get the error:
Traceback (most recent call last):
File "setup.py", line 18, in <module>
with file('version','rt') as FF:
NameError: name 'file' is not defined
which I understand is correct as the file object no longer exists and I should change it to 'open()'.
The concern is that the '2to3' utility does not detect this and leaves the code untouched.
I unfortunately use this idiom throughout my code.
Is this a bug in '2to3' ?
Use the open instead of the file.
It was tempting to use the file() instead of the open() in Python 2.x -- especially for those with OO background. The file() call resembled calling a constructor for creation of a file object. However, it was always recommended to use open() function instead. This may be the reason why 2to3 does not solve the case.
In Python 3, the file is unknown. The file objects are of the _io.TextIOWrapper class:
>>> f = open('a.txt', 'w')
>>> type(f)
<class '_io.TextIOWrapper'>
>>> f.__class__.__name__
'TextIOWrapper'
I'm pretty new to Qt, Python and their combinations. I'm currently writing a QGIS plugin in python (I used QtCreator 2.1 (Qt Designer 4.7) to generate a .ui-file and am now trying to use it for a Quantum GIS plugin that's written in Python 2.5 (and running in the Quantum GIS Python 2.5 console)).
I am running into trouble when loading the ui-file dynamically when the program runs the loadUi() function. What throws me off is that the error occurs outside my script. Does that mean, I'm passing something wrong into it? Where does the error come in? Any hints on what could be wrong?
code_dir = os.path.dirname(os.path.abspath(__file__))
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
This is the Error Code I am getting (minus the first paragraph):
File "C:/Dokumente und Einstellungen/name.name/.qgis/python/plugins\myfile\myfile_gui.py", line 42, in __ init __
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic__init__.py", line 112, in loadUi
return DynamicUILoader().loadUi(uifile, baseinstance)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\Loader\loader.py", line 21, in loadUi
return self.parse(filename)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 768, in parse
actor(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 616, in createUserInterface
self.traverseWidgetTree(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in traverseWidgetTree
handler(self, child)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 233, in createWidget
topwidget.setCentralWidget(widget)
SystemError: error return without exception set
I'm not sure of what could be causing this precise problem, but using .ui files directly has never worked well for me - instead I compile them to python code using pyuic4 (should be in your path if your PyQt4 site-packages are correctly configured. The syntax is along the lines of :-
pyuic4 -o <python output> -x <uic input>
-: resource files can similarly be converted to (not so human-readable) python using :-
pyrrc4 -o <python output> <qrc input>
-: You can then import that python file as a module, not to mention that reading its code can give you clues on how to fiddle with the layout at runtime.
The other upside of this is that you are not having to parse xml at runtime - importing a python module is far quicker and you are not likely to change the ui anywhere near as often as you run the script. If you do find yourself in this situation you can just create a batch to run these before your script/application.
This is the method I use in conjunction with pyInstaller to deploy scripts that will 'just run' on XP, Vista and Windows 7 without modification, and I generate the python modules just before compiling with pyInstaller, so it can be a real time saver.