Running Python Script from C# with IronPython












0















While I am trying to run python code from C# with Iron Python I get some exceptions tried writing code inside C# but it didn't change anything. Is there any other option to run python code inside C#? or Am I doing something wrong with my code? In python everything works great Until I run it from C#



private static string GetBitcoinPrivateKeyFromMnemonic(string mnemonic)
{
var engine = Python.CreateEngine();
ICollection<string> paths = engine.GetSearchPaths();
var dir1 = @"/home/hackslash/.local/lib/python3.7/site-packages";
var dir2 = @"/usr/lib/python3.7";
paths.Add(dir1);
paths.Add(dir2);
engine.SetSearchPaths(paths);
dynamic py = engine.ExecuteFile(@"/home/hackslash/Magnify/MagnifyDevelopment/Python/bitcoin.py");
dynamic bitcoin = py.Bitcoin();
var bitcoinPrivateWIF = bitcoin.generate_bitcoin_private_wif(mnemonic);
return bitcoinPrivateWIF;
}


and I have this file in Python



from btctools import *
import hashlib


class Bitcoin:

@classmethod
def generate_bitcoin_address_from_wif(cls, private_key_wif):
private_key = PrivateKey.from_wif(private_key_wif)
public_key = private_key.to_public()
public_address = public_key.to_address('P2PKH', compressed=False)

return public_address

@classmethod
def generate_bitcoin_private_wif(cls, mnemonic):
hashed_words = hashlib.sha256(mnemonic.encode()).hexdigest()

private_key = PrivateKey.from_hex(hashed_words)
private_wif = private_key.wif(compressed=False)

return private_wif


I get this Exception:
Unhandled Exception:
Microsoft.Scripting.SyntaxErrorException: invalid syntax
at IronPython.Runtime.ThrowingErrorSink.Add (Microsoft.Scripting.SourceUnit sourceUnit, System.String message, Microsoft.Scripting.SourceSpan span, System.Int32 errorCode, Microsoft.Scripting.Severity severity) [0x0001a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message, System.Int32 errorCode) [0x0003a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message) [0x00000] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.String message) [0x00027] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.AddTrailers (IronPython.Compiler.Ast.Expression ret, System.Boolean allowGeneratorExpression) [0x00103] in <0569a20e5dd94f74a766cc11c6214b7c>:0










share|improve this question























  • The indentation of the Python code shown here is wrong. Is it really indented this way?

    – Michael Butscher
    Nov 21 '18 at 20:53











  • Yeah Stack did that thing to my code python code work fine with pycharm

    – MiGle Gurushidze
    Nov 21 '18 at 20:54











  • If there is no way to get a better error description (I'm not used to IronPython) first try to execute a very simple script (e.g. one only containing a single digit like 1). If this works try a reduced version of the actual script. My guess is that from btctools import * imports something with a bad syntax. Maybe the IronPython version doesn't support a used feature of Python 3.7.

    – Michael Butscher
    Nov 21 '18 at 21:13











  • You mean to import all needed file manually without * this?

    – MiGle Gurushidze
    Nov 21 '18 at 21:14











  • No this won't help here. The actual importing (and parsing of the code) happens nevertheless. Just try first the 1 file and then a file only containing from btctools import *.

    – Michael Butscher
    Nov 21 '18 at 21:16
















0















While I am trying to run python code from C# with Iron Python I get some exceptions tried writing code inside C# but it didn't change anything. Is there any other option to run python code inside C#? or Am I doing something wrong with my code? In python everything works great Until I run it from C#



private static string GetBitcoinPrivateKeyFromMnemonic(string mnemonic)
{
var engine = Python.CreateEngine();
ICollection<string> paths = engine.GetSearchPaths();
var dir1 = @"/home/hackslash/.local/lib/python3.7/site-packages";
var dir2 = @"/usr/lib/python3.7";
paths.Add(dir1);
paths.Add(dir2);
engine.SetSearchPaths(paths);
dynamic py = engine.ExecuteFile(@"/home/hackslash/Magnify/MagnifyDevelopment/Python/bitcoin.py");
dynamic bitcoin = py.Bitcoin();
var bitcoinPrivateWIF = bitcoin.generate_bitcoin_private_wif(mnemonic);
return bitcoinPrivateWIF;
}


and I have this file in Python



from btctools import *
import hashlib


class Bitcoin:

@classmethod
def generate_bitcoin_address_from_wif(cls, private_key_wif):
private_key = PrivateKey.from_wif(private_key_wif)
public_key = private_key.to_public()
public_address = public_key.to_address('P2PKH', compressed=False)

return public_address

@classmethod
def generate_bitcoin_private_wif(cls, mnemonic):
hashed_words = hashlib.sha256(mnemonic.encode()).hexdigest()

private_key = PrivateKey.from_hex(hashed_words)
private_wif = private_key.wif(compressed=False)

return private_wif


I get this Exception:
Unhandled Exception:
Microsoft.Scripting.SyntaxErrorException: invalid syntax
at IronPython.Runtime.ThrowingErrorSink.Add (Microsoft.Scripting.SourceUnit sourceUnit, System.String message, Microsoft.Scripting.SourceSpan span, System.Int32 errorCode, Microsoft.Scripting.Severity severity) [0x0001a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message, System.Int32 errorCode) [0x0003a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message) [0x00000] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.String message) [0x00027] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.AddTrailers (IronPython.Compiler.Ast.Expression ret, System.Boolean allowGeneratorExpression) [0x00103] in <0569a20e5dd94f74a766cc11c6214b7c>:0










share|improve this question























  • The indentation of the Python code shown here is wrong. Is it really indented this way?

    – Michael Butscher
    Nov 21 '18 at 20:53











  • Yeah Stack did that thing to my code python code work fine with pycharm

    – MiGle Gurushidze
    Nov 21 '18 at 20:54











  • If there is no way to get a better error description (I'm not used to IronPython) first try to execute a very simple script (e.g. one only containing a single digit like 1). If this works try a reduced version of the actual script. My guess is that from btctools import * imports something with a bad syntax. Maybe the IronPython version doesn't support a used feature of Python 3.7.

    – Michael Butscher
    Nov 21 '18 at 21:13











  • You mean to import all needed file manually without * this?

    – MiGle Gurushidze
    Nov 21 '18 at 21:14











  • No this won't help here. The actual importing (and parsing of the code) happens nevertheless. Just try first the 1 file and then a file only containing from btctools import *.

    – Michael Butscher
    Nov 21 '18 at 21:16














0












0








0








While I am trying to run python code from C# with Iron Python I get some exceptions tried writing code inside C# but it didn't change anything. Is there any other option to run python code inside C#? or Am I doing something wrong with my code? In python everything works great Until I run it from C#



private static string GetBitcoinPrivateKeyFromMnemonic(string mnemonic)
{
var engine = Python.CreateEngine();
ICollection<string> paths = engine.GetSearchPaths();
var dir1 = @"/home/hackslash/.local/lib/python3.7/site-packages";
var dir2 = @"/usr/lib/python3.7";
paths.Add(dir1);
paths.Add(dir2);
engine.SetSearchPaths(paths);
dynamic py = engine.ExecuteFile(@"/home/hackslash/Magnify/MagnifyDevelopment/Python/bitcoin.py");
dynamic bitcoin = py.Bitcoin();
var bitcoinPrivateWIF = bitcoin.generate_bitcoin_private_wif(mnemonic);
return bitcoinPrivateWIF;
}


and I have this file in Python



from btctools import *
import hashlib


class Bitcoin:

@classmethod
def generate_bitcoin_address_from_wif(cls, private_key_wif):
private_key = PrivateKey.from_wif(private_key_wif)
public_key = private_key.to_public()
public_address = public_key.to_address('P2PKH', compressed=False)

return public_address

@classmethod
def generate_bitcoin_private_wif(cls, mnemonic):
hashed_words = hashlib.sha256(mnemonic.encode()).hexdigest()

private_key = PrivateKey.from_hex(hashed_words)
private_wif = private_key.wif(compressed=False)

return private_wif


I get this Exception:
Unhandled Exception:
Microsoft.Scripting.SyntaxErrorException: invalid syntax
at IronPython.Runtime.ThrowingErrorSink.Add (Microsoft.Scripting.SourceUnit sourceUnit, System.String message, Microsoft.Scripting.SourceSpan span, System.Int32 errorCode, Microsoft.Scripting.Severity severity) [0x0001a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message, System.Int32 errorCode) [0x0003a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message) [0x00000] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.String message) [0x00027] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.AddTrailers (IronPython.Compiler.Ast.Expression ret, System.Boolean allowGeneratorExpression) [0x00103] in <0569a20e5dd94f74a766cc11c6214b7c>:0










share|improve this question














While I am trying to run python code from C# with Iron Python I get some exceptions tried writing code inside C# but it didn't change anything. Is there any other option to run python code inside C#? or Am I doing something wrong with my code? In python everything works great Until I run it from C#



private static string GetBitcoinPrivateKeyFromMnemonic(string mnemonic)
{
var engine = Python.CreateEngine();
ICollection<string> paths = engine.GetSearchPaths();
var dir1 = @"/home/hackslash/.local/lib/python3.7/site-packages";
var dir2 = @"/usr/lib/python3.7";
paths.Add(dir1);
paths.Add(dir2);
engine.SetSearchPaths(paths);
dynamic py = engine.ExecuteFile(@"/home/hackslash/Magnify/MagnifyDevelopment/Python/bitcoin.py");
dynamic bitcoin = py.Bitcoin();
var bitcoinPrivateWIF = bitcoin.generate_bitcoin_private_wif(mnemonic);
return bitcoinPrivateWIF;
}


and I have this file in Python



from btctools import *
import hashlib


class Bitcoin:

@classmethod
def generate_bitcoin_address_from_wif(cls, private_key_wif):
private_key = PrivateKey.from_wif(private_key_wif)
public_key = private_key.to_public()
public_address = public_key.to_address('P2PKH', compressed=False)

return public_address

@classmethod
def generate_bitcoin_private_wif(cls, mnemonic):
hashed_words = hashlib.sha256(mnemonic.encode()).hexdigest()

private_key = PrivateKey.from_hex(hashed_words)
private_wif = private_key.wif(compressed=False)

return private_wif


I get this Exception:
Unhandled Exception:
Microsoft.Scripting.SyntaxErrorException: invalid syntax
at IronPython.Runtime.ThrowingErrorSink.Add (Microsoft.Scripting.SourceUnit sourceUnit, System.String message, Microsoft.Scripting.SourceSpan span, System.Int32 errorCode, Microsoft.Scripting.Severity severity) [0x0001a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message, System.Int32 errorCode) [0x0003a] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.Int32 start, System.Int32 end, System.String message) [0x00000] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.ReportSyntaxError (System.String message) [0x00027] in <0569a20e5dd94f74a766cc11c6214b7c>:0
at IronPython.Compiler.Parser.AddTrailers (IronPython.Compiler.Ast.Expression ret, System.Boolean allowGeneratorExpression) [0x00103] in <0569a20e5dd94f74a766cc11c6214b7c>:0







c# python ironpython






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 20:38









MiGle GurushidzeMiGle Gurushidze

113




113













  • The indentation of the Python code shown here is wrong. Is it really indented this way?

    – Michael Butscher
    Nov 21 '18 at 20:53











  • Yeah Stack did that thing to my code python code work fine with pycharm

    – MiGle Gurushidze
    Nov 21 '18 at 20:54











  • If there is no way to get a better error description (I'm not used to IronPython) first try to execute a very simple script (e.g. one only containing a single digit like 1). If this works try a reduced version of the actual script. My guess is that from btctools import * imports something with a bad syntax. Maybe the IronPython version doesn't support a used feature of Python 3.7.

    – Michael Butscher
    Nov 21 '18 at 21:13











  • You mean to import all needed file manually without * this?

    – MiGle Gurushidze
    Nov 21 '18 at 21:14











  • No this won't help here. The actual importing (and parsing of the code) happens nevertheless. Just try first the 1 file and then a file only containing from btctools import *.

    – Michael Butscher
    Nov 21 '18 at 21:16



















  • The indentation of the Python code shown here is wrong. Is it really indented this way?

    – Michael Butscher
    Nov 21 '18 at 20:53











  • Yeah Stack did that thing to my code python code work fine with pycharm

    – MiGle Gurushidze
    Nov 21 '18 at 20:54











  • If there is no way to get a better error description (I'm not used to IronPython) first try to execute a very simple script (e.g. one only containing a single digit like 1). If this works try a reduced version of the actual script. My guess is that from btctools import * imports something with a bad syntax. Maybe the IronPython version doesn't support a used feature of Python 3.7.

    – Michael Butscher
    Nov 21 '18 at 21:13











  • You mean to import all needed file manually without * this?

    – MiGle Gurushidze
    Nov 21 '18 at 21:14











  • No this won't help here. The actual importing (and parsing of the code) happens nevertheless. Just try first the 1 file and then a file only containing from btctools import *.

    – Michael Butscher
    Nov 21 '18 at 21:16

















The indentation of the Python code shown here is wrong. Is it really indented this way?

– Michael Butscher
Nov 21 '18 at 20:53





The indentation of the Python code shown here is wrong. Is it really indented this way?

– Michael Butscher
Nov 21 '18 at 20:53













Yeah Stack did that thing to my code python code work fine with pycharm

– MiGle Gurushidze
Nov 21 '18 at 20:54





Yeah Stack did that thing to my code python code work fine with pycharm

– MiGle Gurushidze
Nov 21 '18 at 20:54













If there is no way to get a better error description (I'm not used to IronPython) first try to execute a very simple script (e.g. one only containing a single digit like 1). If this works try a reduced version of the actual script. My guess is that from btctools import * imports something with a bad syntax. Maybe the IronPython version doesn't support a used feature of Python 3.7.

– Michael Butscher
Nov 21 '18 at 21:13





If there is no way to get a better error description (I'm not used to IronPython) first try to execute a very simple script (e.g. one only containing a single digit like 1). If this works try a reduced version of the actual script. My guess is that from btctools import * imports something with a bad syntax. Maybe the IronPython version doesn't support a used feature of Python 3.7.

– Michael Butscher
Nov 21 '18 at 21:13













You mean to import all needed file manually without * this?

– MiGle Gurushidze
Nov 21 '18 at 21:14





You mean to import all needed file manually without * this?

– MiGle Gurushidze
Nov 21 '18 at 21:14













No this won't help here. The actual importing (and parsing of the code) happens nevertheless. Just try first the 1 file and then a file only containing from btctools import *.

– Michael Butscher
Nov 21 '18 at 21:16





No this won't help here. The actual importing (and parsing of the code) happens nevertheless. Just try first the 1 file and then a file only containing from btctools import *.

– Michael Butscher
Nov 21 '18 at 21:16












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420133%2frunning-python-script-from-c-sharp-with-ironpython%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420133%2frunning-python-script-from-c-sharp-with-ironpython%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?