Closed worldsoft closed 3 years ago
Unfortunately I can't figure out the problem from your description alone. Can you please copy paste the line(s) of code you're using to call Python with (e.g., pyCommunicator.runResults(...)
) and the text from the AnyLogic console with the error?
when running the script using the command line of this file
def initializing(config: GlobalCongig): print(f"Success ")
However, when I run the same file using the command
Attempt helpAttempt = PyCommunicator.runFile(PythonCommandType.PYTHON, "main.py"); traceln(helpAttempt.getFeedback());
I get an error:
File "main.py", line 3
def initializing(config: GlobalCongig):
^
SyntaxError: invalid syntax
Then I tried to fix the error by removing the colon:
def initializing(config): print(f"Hello")
and a new error appeared: File "main.py", line 4
print(f"Hello")
^
SyntaxError: invalid syntax I am using python 3.7. And it runs through the command line without errors. Please tell me what I'm doing no so.
I would make sure that python
points to the expected version, specifically from within AnyLogic. I know you said you tried from the command line, but this may still differ in some environments that handle system paths differently (I've noticed this moreso with Macs).
I reproduced what you had, minus the GlobalCongig
object, which I just set to typing's Any
. I had it first print out the version it's using (in a separate file) and then print out "Success" along with any arg passed (True by default). It worked with Python 3.6 and 3.7 both statically and nonstatically.
Results:
Here's the model I used if you want to try it yourself. Model124.zip
Thanks. Solved the problem using the command pyCommunicator.runResults
You're welcome - but I'm a bit confused, as it should still work statically. If you ran the model I provided, did it print out the correct version (ie a version of Python >= 3.6)?
Closing, as it's solved. But I am curious about the output to see where the underlying issue might have been.
when run through the command line, the code runs without error. However, when I use open the file with the pyCommunicator.run command an error comes out syntax error def (config: config). I thought that the problem is in the python version. However, after installing version 3.7, the error remained the same.