NetLogo / Python-Extension

Python extension for NetLogo
26 stars 15 forks source link

Python Extension - errors when python executable is not properly configured #19

Closed cynthia-w closed 2 years ago

cynthia-w commented 4 years ago

After pressing "setup", I get the following error:

NetLogo is unable to supply you with more details about this error. Please report the problem at https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the contents of this window into your report.

java.lang.IllegalStateException at scala.util.matching.Regex$MatchIterator.ensure(Regex.scala:850) at scala.util.matching.Regex$MatchIterator.groupCount(Regex.scala:869) at org.nlogo.extensions.py.PythonBinary$.$anonfun$fromFile$2(PythonExtension.scala:150) at scala.Option.flatMap(Option.scala:188) at org.nlogo.extensions.py.PythonBinary$.fromFile(PythonExtension.scala:148) at org.nlogo.extensions.py.PythonSubprocess$.$anonfun$pythons$3(PythonExtension.scala:253) at scala.collection.immutable.Stream.flatMap(Stream.scala:489) at org.nlogo.extensions.py.PythonSubprocess$.pythons(PythonExtension.scala:253) at org.nlogo.extensions.py.PythonSubprocess$.$anonfun$python3$4(PythonExtension.scala:246) at scala.Option.orElse(Option.scala:306) at org.nlogo.extensions.py.PythonSubprocess$.python3(PythonExtension.scala:246) at org.nlogo.extensions.py.PythonSubprocess$.anyPython(PythonExtension.scala:248) at org.nlogo.extensions.py.PythonExtension.$anonfun$load$5(PythonExtension.scala:512) at org.nlogo.extensions.py.FindPython.report(PythonExtension.scala:590) at org.nlogo.extensions.py.FindPython.report(PythonExtension.scala:585) at org.nlogo.prim._externreport.report(_externreport.java:31) at org.nlogo.nvm.Argument.unsafeGet(Argument.scala:33) at org.nlogo.nvm.Argument.getString(Argument.scala:111) at org.nlogo.extensions.py.SetupPython$.$anonfun$perform$1(PythonExtension.scala:549) at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237) at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36) at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33) at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198) at scala.collection.TraversableLike.map(TraversableLike.scala:237) at scala.collection.TraversableLike.map$(TraversableLike.scala:230) at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:198) at org.nlogo.extensions.py.SetupPython$.perform(PythonExtension.scala:549) at org.nlogo.prim._extern.perform(_extern.java:36) at org.nlogo.nvm.Context.stepConcurrent(Context.java:107) at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.scala:65) at org.nlogo.job.JobThread.runPrimaryJobs(JobThread.scala:133) at org.nlogo.job.JobThread.$anonfun$run$1(JobThread.scala:68) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at scala.util.control.Exception$Catch.apply(Exception.scala:228) at org.nlogo.api.Exceptions$.handling(Exceptions.scala:41) at org.nlogo.job.JobThread.run(JobThread.scala:66)

NetLogo 6.1.1 main: org.nlogo.app.AppFrame thread: JobThread Java HotSpot(TM) 64-Bit Server VM 1.8.0_202 (Oracle Corporation; 1.8.0_202-b08) operating system: Windows 10 10.0 (amd64 processor) Scala version 2.12.8 JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized) model: Python Basic Example

09:22:25.076 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0 09:22:25.060 RuntimeErrorEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 09:22:24.871 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0 09:22:24.856 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:24.856 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0

brandesNW commented 4 years ago

Hi Cynthia,

I am sorry you encountered a problem with the Python extension.

I was able to reproduce your problem on a Windows system, but not my Mac system.

The problem occurs when NetLogo is trying to determine the location of your python installation. As a workaround to this problem, you can set this location permanently by using the configuration menu under the Python toolbar menu that appears when you use a model that uses the Python extension. For more details see the documentation section Configuring Pythonhttps://ccl.northwestern.edu/netlogo/docs/py.html#configuring for help.

To determine the location of your python installation in a Windows system, open a cmd window and type ‘where python’ (without quotes)

where python In my case the result was C:\ProgramData\Anaconda3\python.exe Which I entered in the. Configuration window for python3 Note: typing C:\ProgramData\Anaconda3\python.exe in the cmd window puts you into the python environment, and will show you whether you are using python2 or python3. Use “quit()” to exit.

Note: for linux or Mac users you can determine the location of the executable by using ‘which python’

Best, Aaron

-- Aaron Brandes, Software Developer Center for Connected Learning and Computer-Based Modeling

From: cynthia-w notifications@github.com Reply-To: NetLogo/NetLogo reply@reply.github.com Date: Thursday, October 15, 2020 at 9:27 AM To: NetLogo/NetLogo NetLogo@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [NetLogo/NetLogo] Python Basic Example: Internal Error (#1863)

After pressing "setup", I get the following error:

NetLogo is unable to supply you with more details about this error. Please report the problem at https://github.com/NetLogo/NetLogo/issueshttps://urldefense.com/v3/__https:/github.com/NetLogo/NetLogo/issues__;!!Dq0X2DkFhyF93HkjWTBQKhk!BQN8F3rGi5kJcncy7LJpbQZtA5HLMo7PmPT1hKhir4UM9qSoa-lXVOTJ-RFLB_TDJ2snlc5fag$, or to bugs@ccl.northwestern.edumailto:bugs@ccl.northwestern.edu, and paste the contents of this window into your report.

java.lang.IllegalStateException at scala.util.matching.Regex$MatchIterator.ensure(Regex.scala:850) at scala.util.matching.Regex$MatchIterator.groupCount(Regex.scala:869) at org.nlogo.extensions.py.PythonBinary$.$anonfun$fromFile$2(PythonExtension.scala:150) at scala.Option.flatMap(Option.scala:188) at org.nlogo.extensions.py.PythonBinary$.fromFile(PythonExtension.scala:148) at org.nlogo.extensions.py.PythonSubprocess$.$anonfun$pythons$3(PythonExtension.scala:253) at scala.collection.immutable.Stream.flatMap(Stream.scala:489) at org.nlogo.extensions.py.PythonSubprocess$.pythons(PythonExtension.scala:253) at org.nlogo.extensions.py.PythonSubprocess$.$anonfun$python3$4(PythonExtension.scala:246) at scala.Option.orElse(Option.scala:306) at org.nlogo.extensions.py.PythonSubprocess$.python3(PythonExtension.scala:246) at org.nlogo.extensions.py.PythonSubprocess$.anyPython(PythonExtension.scala:248) at org.nlogo.extensions.py.PythonExtension.$anonfun$load$5(PythonExtension.scala:512) at org.nlogo.extensions.py.FindPython.report(PythonExtension.scala:590) at org.nlogo.extensions.py.FindPython.report(PythonExtension.scala:585) at org.nlogo.prim._externreport.report(_externreport.java:31) at org.nlogo.nvm.Argument.unsafeGet(Argument.scala:33) at org.nlogo.nvm.Argument.getString(Argument.scala:111) at org.nlogo.extensions.py.SetupPython$.$anonfun$perform$1(PythonExtension.scala:549) at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237) at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36) at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33) at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198) at scala.collection.TraversableLike.map(TraversableLike.scala:237) at scala.collection.TraversableLike.map$(TraversableLike.scala:230) at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:198) at org.nlogo.extensions.py.SetupPython$.perform(PythonExtension.scala:549) at org.nlogo.prim._extern.perform(_extern.java:36) at org.nlogo.nvm.Context.stepConcurrent(Context.java:107) at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.scala:65) at org.nlogo.job.JobThread.runPrimaryJobs(JobThread.scala:133) at org.nlogo.job.JobThread.$anonfun$run$1(JobThread.scala:68) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at scala.util.control.Exception$Catch.apply(Exception.scala:228) at org.nlogo.api.Exceptions$.handling(Exceptions.scala:41) at org.nlogo.job.JobThread.run(JobThread.scala:66)

NetLogo 6.1.1 main: org.nlogo.app.AppFrame thread: JobThread Java HotSpot(TM) 64-Bit Server VM 1.8.0_202 (Oracle Corporation; 1.8.0_202-b08) operating system: Windows 10 10.0 (amd64 processor) Scala version 2.12.8 JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized) model: Python Basic Example

09:22:25.076 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0 09:22:25.060 RuntimeErrorEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:25.060 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 09:22:24.871 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0 09:22:24.856 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0 09:22:24.856 InterfaceGlobalEvent (org.nlogo.window.InputBoxWidget) AWT-EventQueue-0

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/NetLogo/NetLogo/issues/1863__;!!Dq0X2DkFhyF93HkjWTBQKhk!BQN8F3rGi5kJcncy7LJpbQZtA5HLMo7PmPT1hKhir4UM9qSoa-lXVOTJ-RFLB_TDJ2sbZ_V_yQ$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/ANSUO2VQQUDON4D4PLKQDZLSK32CFANCNFSM4SR7XHPQ__;!!Dq0X2DkFhyF93HkjWTBQKhk!BQN8F3rGi5kJcncy7LJpbQZtA5HLMo7PmPT1hKhir4UM9qSoa-lXVOTJ-RFLB_TDJ2t4t4giIg$.

brandesNW commented 4 years ago

This problem is reproducable on a Windows system, but not my Mac system.

As a workaround to this problem, the user can set the location of the python executable permanently by using the configuration menu under the Python toolbar menu that appears when you use a model that uses the Python extension.

For more details see the documentation section [Configuring Python] (https://ccl.northwestern.edu/netlogo/docs/py.html#configuring) for help.

To determine the location of the python installation in a Windows system, open a cmd window and type ‘where python’ (without quotes) where python

In my case the result was C:\ProgramData\Anaconda3\python.exe which I entered in the. Configuration window for python3

Note: typing C:\ProgramData\Anaconda3\python.exe in the cmd window puts you into the python environment, and will show you whether you are using python2 or python3. Use “quit()” to exit.

Note: for linux or Mac users you can determine the location of the executable by using ‘which python’

cynthia-w commented 4 years ago

Thank you so much for your help Aaron! A detailed response and easy to follow. Deeply appreciate it. Have a great day!!

qiemem commented 4 years ago

Reopening because this does appear to be a bug, even if there's a workaround.

brandesNW commented 3 years ago

I recently encountered a similar problem while running the extension tests in sbt on MacOS

netlogo/testOnly *TestExtensions -- -z "py::np-array-convert-to-lists-python3" resulted in the error

py::np-array-convert-to-lists-python3 FAILED [info] org.nlogo.headless.LanguageTestException: The test errored on the following line: py:runresult "np.array([1,2,3])" [info] ... [info] Cause: org.nlogo.nvm.WrappedExtensionException: Extension exception: module 'numpy' has no attribute 'array' [info] at org.nlogo.prim._externreport.report(_externreport.java:35)

I found this explanation in StackOverflow

You are most likely having a file called numpy.py in your working directory which shadows the real numpy module. Rename that file and remove its numpy.pyc file.

I was also able to reproduce the problem with the following simple NetLogo program:

extensions [ py ]
to setup
  py:setup py:python
  py:run "import numpy as np"
  show py:runresult "np.array([1,2,3])"
end

Both problems disappeared when I used the NetLogo Python -> Configure option to set the path for the Python 3 executable.

When I tested the problem in Windows, I got an error message very similar to cynthia-w's.

NetLogo is unable to supply you with more details about this error. Please report the problem at https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the contents of this window into your report.

java.lang.IllegalStateException at scala.util.matching.Regex$MatchIterator.ensure(Regex.scala:850) at scala.util.matching.Regex$MatchIterator.groupCount(Regex.scala:869) at org.nlogo.extensions.py.PythonBinary$.$anonfun$fromFile$2(PythonExtension.scala:150) at scala.Option.flatMap(Option.scala:271) at org.nlogo.extensions.py.PythonBinary$.fromFile(PythonExtension.scala:148) at org.nlogo.extensions.py.PythonSubprocess$.$anonfun$pythons$3(PythonExtension.scala:248) at scala.collection.immutable.Stream.flatMap(Stream.scala:489) at org.nlogo.extensions.py.PythonSubprocess$.pythons(PythonExtension.scala:248) at org.nlogo.extensions.py.PythonSubprocess$.$anonfun$python3$4(PythonExtension.scala:241) at scala.Option.orElse(Option.scala:447) at org.nlogo.extensions.py.PythonSubprocess$.python3(PythonExtension.scala:241) at org.nlogo.extensions.py.PythonSubprocess$.anyPython(PythonExtension.scala:243) at org.nlogo.extensions.py.PythonExtension.$anonfun$load$5(PythonExtension.scala:507) at org.nlogo.extensions.py.FindPython.report(PythonExtension.scala:613) at org.nlogo.extensions.py.FindPython.report(PythonExtension.scala:608) at org.nlogo.prim._externreport.report(_externreport.java:31) at org.nlogo.nvm.Argument.unsafeGet(Argument.scala:33) at org.nlogo.nvm.Argument.getString(Argument.scala:120) at org.nlogo.extensions.py.SetupPython$.$anonfun$perform$1(PythonExtension.scala:543) at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:285) at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36) at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33) at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198) at scala.collection.TraversableLike.map(TraversableLike.scala:285) at scala.collection.TraversableLike.map$(TraversableLike.scala:278) at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:198) at org.nlogo.extensions.py.SetupPython$.perform(PythonExtension.scala:543) at org.nlogo.prim._extern.perform(_extern.java:36) at org.nlogo.nvm.Context.stepConcurrent(Context.java:107) at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.scala:65) at org.nlogo.job.JobThread.runPrimaryJobs(JobThread.scala:133) at org.nlogo.job.JobThread.$anonfun$run$1(JobThread.scala:68) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at scala.util.control.Exception$Catch.apply(Exception.scala:228) at org.nlogo.api.Exceptions$.handling(Exceptions.scala:41) at org.nlogo.job.JobThread.run(JobThread.scala:66)

NetLogo 6.2.0 main: org.nlogo.app.AppFrame thread: JobThread OpenJDK 64-Bit Server VM 1.8.0_275 (BellSoft; 1.8.0_275-b01) operating system: Windows 10 10.0 (amd64 processor) Scala version 2.12.12 JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized) model: python-array

01:32:40.523 RuntimeErrorEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:40.523 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:40.000 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0 01:32:40.000 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:39.900 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0 01:32:39.799 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:39.599 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:39.394 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:39.179 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 01:32:38.978 ModelSavedEvent (org.nlogo.app.MenuBar) AWT-EventQueue-0

brandesNW commented 3 years ago

I think we should consider the following change to the py extension - If a path to the python executable is not configured, we do not attempt to find one. Instead we issue a message explaining that the path must be set, and include a link to the documentation.

It appears that in the current situation users are left with a cryptic error message. They may also find that the extension works for some models and not others.

LaCuneta commented 2 years ago

Closing this as a duplicate of #23. Really this one was first, but that's the one I saw when I applied the fixes. See my comments in that issue for more info on the changes released in 0.5.1.