So, i've been trying to compile a program using sconstruct, but i'm facing a problem.
I got the following error when trying to compile a program using sconstruct.
D:\RN ENGINE - REV #1\neo>scons
scons: Reading SConscript files ...
File "sys/scons\scons_utils.py", line 19
except OSError, x:
^
SyntaxError: invalid syntax
I have tried to look for the file where the error is occured, which is scons_utils.py, but i didn't manage to find it, and the documentation didn't helped me very well.
Is this a bug on the sconstruct itself, or i did something wrong? Thanks.
If something else is required in order to solve this, i won't hesitate to give it.
scons_utils.py is not a SCons file. So it's likely part of whatever you're trying to build.
Likely you're using python 3.5+ with a newer SCons, and previously you were using python 2.7 and older SCons.
SO the issue you see (once you find the file) is python 2.7 vs python 3.5+.
Try running again with --debug=stacktrace which should hopefully give you the full path to scons_utils.py
Change that line to:
except OSError as x:
Related
I just recently updated Cython from 0.29.24 to 3.0.0a11 and I was getting compilation errors due to functions that were using Dict type hints. With the previous versions, I never had any issues of this type (no pun intended). I compile my entire python project by building Extensions using cythonize in a setup.py file. I am using Python 3.9.13.
After doing some reading I attempted to solve the issues I was having by using the compiler directive as follows:
import cython
#cython.annotation_typing(False)
def my_function_with_type_hints(this_object: Dict) -> Dict:
pass
Compilation succeeded although I have not tested my compiled code yet. I returned to development to test some new code and now I am unable to run code in interpeter mode because Cython is complaining "module 'cython' has no attribute 'annotation_typing'". I confirmed (via pip freeze) that Cython==3.0.0a11 is installed in my environment and that my environment is activated (in vscode).
My questions:
Did I fix the typing issue correctly using the compiler directive or am I not understanding the problem fully?
How should I be using compiler directives in interpreter mode? Do I need another decorator that conditionally includes the cython directive?
Thank you in advance for any help!
I can't figure out what I made wrong I look on almost every forum but I only found answer for linux. I'm trying to compile a python project. It my first time I compile a project I would really appreciate if someone could help me.
I start with cython so I have a .c file of my project and I download gcc add it path into json and I run it. And TADA I have a beautiful error message.
There is some code I want to turn into an exe. I have used Pyinstaller and I manage getting an exe that runs. The platform is Win10, Python version 3.6, devs with Spyder.
At some point in the code, the following lines pose an issue with the exe (not in script mode):
from formulas import parser as formulasparser
# code including classes
# in a function:
t = 'x<1' # any string that is a 'formula', here provided for the example
parser_ = formulasparser.Parser()
# the exe works so far, I have traced the code and can read the messages in the windows cmd
func = parser_.ast(t)
# nothing happens and no way to get a trace; there is an issue, and I have no clue which one as there
# is no error message.
So, it seems that the ast function won't work for some reason. Can anyone help me? I need to distribute this application and it does not work because of this right now.
Thanks for your help.
Well, someone seems to have faced a somewhat similar issue on the Pyinstaller mailing list.
So: a hook file is actually needed. I created a directory called pyinstallerhooks with a file called hook-formulas.py inside.
The file itself contains:
from PyInstaller.utils.hooks import collect_all
datas, binaries, hiddenimports = collect_all('formulas')
and this is it.
When calling pyinstaller, use the following command:
pyinstaller --additional-hooks-dir pathtoyourdir -F yoursrcipt.py
Pyinstaller fetches the relevant dependencies for the formulas package and it shoudl work.
I have been working using pyttsx3 on win7 64bit python 3.4.3. Everything is good with the .py script I made using pyttsx3 module (works fine alone).
The problem comes when I compile it with pyinstaller. I got an error saying "pyttsx3.drivers not found" and I fixed that by using a .spec file with hiddenimports. Then I got an error that says pywintypes.com_error:(-2147352573,member not found,none,none).
I found on github that someone by the name #natambashat fixed it by commenting out the pyi-rth-win32comgenpy.py runtime hook because that's only needed for pyttsx. But that didnt work for me, I still get the same error. Can you please help me?
You cannot compile a script that contains pyttsx3 with pyinstaller because, pyinstaller like all compilers do not have every single python module. Here is a link that shows you all the compatible packages for pyinstaller.
Another option is py2exe. I am not a Windows user, so I don't know how to use it. But it supposedly supports pyttsx.
Another option though untested by me, is to download the pyttsx source code, put it into your project directory, import it in the code that uses pyttsx, then compile it with pyinstaller using:
pyinstaller --onefile app.py
Eureka!!i fixed it! Am gonna write what i did step by step in case some one come-across to the same problem.
1.i made a hook-pyttsx3.py file and commented out the pyi-rth-win32comgenpy.py file(have a look at this link of github.( instead of commenting out,you can also remove the line "win32:pyi-rth-win32comgenpy.py" from the rthooks.DAT file in ...Lib/sitepackages/pyinstaller/loader/rthooks).
2.go to ...Lib/sitepackages/Win32com/client/dynamic.py and to the _GetDeskInvokeType function.Replace the last line(return invoke_type) with return varkind.
->For some people just step 1 works,but for me i need to apply step2.I found somewhere in sourceforge(i dont remember the link),when compiling a script that involves win32,pywin32 version 221 and 220 gives the pywintypes error i mentioned above.But pywin32 version 219 doesnt give this error(i am using pywin32 v221).And the reason behind that is,in the function i mentioned in step2,return invoke_type is only on version 221 and 220 but the return on v219 is return varkind.I don't know why this differece came if it gives such errors!
EDIT:This link Is better than the above i gave.
I don't exactly know what I did, but seems like I broke my build system.
$ scons install
scons: Reading SConscript files ...
File "<string>", line 1
I_���.�K
H�4����Ǐ��U)�f���R�f���ў�U)�f���R�f���ў�
^
SyntaxError: invalid syntax
The unprintable characters are intended.
The bad thing is: Even resetting on a "known as working" version does not help, as well as using the options like --debug=stacktrace. My version control system (mercurial) does not show changes in the SCons files and I don't know how to proceed. Any hints how to make mercurial print the names of the files it's working on to find out what's happening?
My next step would be to make a new clone of the project (which hopefully builds), but I'm curious what's wrong here.
UPDATE
The problem disappeared when I updated to Ubuntu 12.04. "Disappeared" means in this case, that suddenly I've been able to execute the scons --clean command after which I was able to rebuild my project again. Sadly I cannot reproduce the error so that finally I don't know what caused it because it worked for several months and none of my colleagues had such a strange error before.
This is an excerpt of my script:
vars = Variables( "variables.cache" )
vars.Add( "CXX", "use this c++ compiler", "/usr/bin/g++" )
# (other stuff added to vars)
env = Environment( variables = vars ) # <-- this line caused the error
In the trouble fixing this I got the impression that after updating, Python was able to give me a better error message and the message was (trying to remember it) that vars is in some way invalid. So maybe the problem was in variables.cache, I don't know. Maybe I should just have deleted this file (which I did not) to get rid of the error.
Try executing scons with warnings, as follows:
# scons --warn=all
If this doesnt help, you could try a more old-school approach and put some print statements in the SConstruct to see whats happening and when/where the problem occurs.
You could also try cleaning the entire project and removing/renaming the .sconsdb.lite in the root project.
UPDATE:
I recently had a problem because the version of Python was changed from 2.6 to 2.7 and the error handling changed completely. So, try putting a python try/except block around everything (or at least the strategic parts) in your SConstruct and print the exceptions (if any) that are thrown.
If none of these work, try posting the SConstruct here.
Code example from my SConstruct demonstrating how I found my error with a Python try/except block. The BuildError exception gave me a stack trace. There are more Exceptions that you can "catch".
...
try:
SConscript(
os.path.join(moduleDir, 'SConscript'), # sub-directory SConscript to load
variant_dir = '#%s' % os.path.join(env['variantDir'], dir), # path relative to this script where to put built files
exports = ['env'], # which variables to export to sub-directory build
duplicate = 0) # dont duplicate source files in variant_dir
except SCons.Errors.BuildError as be:
print "*** BuildError exception processing module: %s, %s" % (moduleDir, be.__str__())
raise
except:
print "*** Unhandled exception processing module: %s" % moduleDir
raise