zabirauf / icsharp

C# kernel for Jupyter
Other
278 stars 62 forks source link

Console.WriteLine does not print output in the notebook #4

Closed awb99 closed 6 years ago

awb99 commented 9 years ago

I think you can register for Console Printouts via Trace.Listener.Add. Here is a snipped that use to display a virtual console:

    #region  HelperClass TConsoleTraceListener
    public class TConsoleTraceListener : TraceListener
    {
        #region Variables
        TConsole _parent;
        #endregion

        #region Constructor
        public TConsoleTraceListener (TConsole parent)
        {
            _parent = parent;
            //Debug.Listeners.Clear ();
            //Debug.Listeners.Add (this);
            //Trace.Listeners.Clear ();
            Trace.Listeners.Add (this);
        }
        #endregion

        #region TraceListener Overrides
        override public void Write(string message) 
        {
            try
            {
                _parent.WriteLine (message);
            }
            catch (Exception ex)
            {
                ;
                Console.Write ("Ex="+ex.Message );
            }
        }
        override public void WriteLine(string message) 
        {     
            try
            {
                _parent.WriteLine (message);
            }
            catch (Exception ex)
            {
                ;
                Console.Write ("Ex="+ex.Message );
            }
        }
        #endregion
    }
    #endregion
den-run-ai commented 9 years ago

@awb99 did you get icsharp working with ipython/jupyter? if yes, which versions?

awb99 commented 9 years ago

I did not. But I am still looking into it. I love IPhython, and I cannot understand why there seems to be almost nobody out there who wants to use c# in Jupyter.

den-run-ai commented 9 years ago

I started a discussion here: https://groups.google.com/forum/#!topic/jupyter/VsCF9xHNp6Y

zabirauf commented 9 years ago

@awb99 Thanks for opening the issue. I will first look into making it work with the update ipython. Feel free to send a pull request if you figure out the issue and have a fix.

awb99 commented 9 years ago

I think one has two problems to solve: 1. running a C# shell in a REPL mode in a linux terminal. (I think I could get this done). This mainly defines the syntax and can print out the status of variables to Console. 2. integration with Jupyter. For this one needs to study more the interface that Jupyter requieres, and then implement it... Both tasks should be doable. And both tasks will have lots implementation issues...

awb99 commented 9 years ago

ICSharp seems to implement a ZMQ messages that are sent via JSON. What I dont understand why building it needs Python. Should be a pure .net application...

den-run-ai commented 9 years ago

@awb99 I built ICSHARP using VS 2015 with GitHub extension, just cloned the repository. I do not think that Python is required for build. I did have to make some changes (add alias for MonoCSharp and replace deprecated calls) and install 3rd party packages using nuget console in VS 2015. But the fun part is then launching jupyter/ipython notebook. Did you succeed in doing so?

awb99 commented 9 years ago

Ahh.. I think now I understand: The notes in the README regarding INSTALLATION are ONLY relevant AFTER the solution has been compiled! Monodevelop has problems in getting the ScriptCS dependencies. It might be because it does not trust the NuGet links? I am usting the Manjaro Linux which is a rolling distribution based on ARCH; so I believe I have the latest versions of all components. I wil try to compile ScriptCs separately, and then in iICSharp just reference the dlls. I will revert shortly.

zabirauf commented 9 years ago

To compile

  1. Clone the project (recursive so that submodule is cloned as well)
  2. Open the solution
  3. Right click on solution and select manage dependencies
    1. Select option to restore nuget packages
  4. Open CMD and navigate to Engine and run build.cmd
  5. Compile icsharp

This will build the icsharp

zabirauf commented 9 years ago

@awb99 as @denfromufa stated python is not required, icsharp is a pure c# project. The instruction in README is to run icsharp as ipython kernel.

awb99 commented 9 years ago

Thank you so much guys!! With clone recursively with ./Engine/build.sh I now managed to build the engine, and the project now builds with MonoDevelop! So will see if I manage to run it in Jupyter..

awb99 commented 9 years ago

All dlls are compiled correctyly now... So now it is to integrate icsharp with Jupyter. Seems that Chocholatey is pure windows package manager. So I am going to investigate how to integrate engines with Jupyter...

den-run-ai commented 9 years ago

@awb99 looks like ICSHARP is not compatible with latest Jupyter protocol, see the errors I'm getting here: https://github.com/zabirauf/icsharp/issues/5

awb99 commented 9 years ago

Ok. So the only thing to find out for me then is, which of the ICsharp dlls I need to copy where, so that they work under linux. The cholcolatey config only works on Windows I believe.

awb99 commented 9 years ago

I am working on the linux settings file for icsharp. I think witht he Chocolatey install, you just amend a ipython settings file. What I havent figured out, is how to call the binary file. In mono you need to call the app mono icsharp.exe Just calling icsharp.exe will not get it done.

den-run-ai commented 9 years ago

I think we should build conda/wheel package for cross-platform installation

On Fri, Sep 11, 2015, 12:37 PM awb99 notifications@github.com wrote:

I am working on the linux settings file for icsharp. I think witht he Chocolatey install, you just amend a ipython settings file. What I havent figured out, is how to call the binary file. In mono you need to call the app mono icsharp.exe Just calling icsharp.exe will not get it done.

— Reply to this email directly or view it on GitHub https://github.com/zabirauf/icsharp/issues/4#issuecomment-139609207.

awb99 commented 9 years ago

I will first try to get it to work... I guess the last version of IPython that should work with icsharp is 2.4.1 I cannot find this verion in debian or arch packets, so I will try to build this version of IPython and study the sources; perhaps I find out how the kernel expects the app parameters.

awb99 commented 9 years ago

I posted on the Jupyter forum.. I need to know if I can pass paramete, as this is how mono apps are called on Unix...

awb99 commented 9 years ago

I am not sure if going with IPython 2.4.1 is the way to go. It is reasonable simple to find this version, and to compile it. However, to get the old version of PyZMQ to get running is not so easy. The sudo pip install pyzmq==2.1.11 fails... I believe I ned to go to an other version of gcc too... Ahhhh

den-run-ai commented 9 years ago

According to Matthias ipython 3 should have adapters for kernels from ipython 2

On Fri, Sep 11, 2015, 4:35 PM awb99 notifications@github.com wrote:

I am not sure if going with IPython 2.4.1 is the way to go. It is reasonable simple to find this version, and to compile it. However, to get the old version of PyZMQ to get running is not so easy. The sudo pip install pyzmq==2.1.11 fails... I believe I ned to go to an other version of gcc too... Ahhhh

— Reply to this email directly or view it on GitHub https://github.com/zabirauf/icsharp/issues/4#issuecomment-139666983.

awb99 commented 9 years ago

I think it is not only Console.WriteLine that does not work, but also undefined Variables. Strangely EXCEPTIONS do work. On Mono I can see the Console.WriteLine Output in the shell, so redirecting this should be easy. See the attached screenshot

Not sure if this error appears also on windows or not: [W 15:24:10.431 NotebookApp] Timeout waiting for kernel_info reply from 00c51217-4953-4e1e-ba44-c902ded0e81f

behavior on mono