8000 TypeError when running ReadMe example · Issue #554 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

TypeError when running ReadMe example #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fgiaret opened this issue Oct 9, 2017 · 7 comments
Closed

TypeError when running ReadMe example #554

fgiaret opened this issue Oct 9, 2017 · 7 comments

Comments

@fgiaret
Copy link
fgiaret commented Oct 9, 2017

Hi, I'm trying to embed Python in a C# project with Visual Studio (I'm very new both to C# and GitHub) and I started running the numpy example from the Readme file. After the lines:

"dynamic a = np.array(new List { 1, 2, 3 });
dynamic b = np.array(new List { 6, 5, 4 }, dtype: np.int32);"

I get the following error:
{"TypeError : int() argument must be a string, a bytes-like object or a number, not '0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'"}.

I have the following settings:

  • Pythonnet version: 2.3.0 for Python 3.6 (64 bit), installed with pip;
  • Python version: 3.6.1 (64 bit) with Anaconda 3;
  • Visual Studio 2015;
  • Operating System: Windows 7

I've seen issue #249 reporting the same error, but still wasn't able to fix this. It would be great if someone could help me,

Thank you!

@den-run-ai
Copy link
Contributor
den-run-ai commented Oct 9, 2017

@fgiaret this has not been released yet, so you need to install pythonnet from master. Download the zip of master branch, unpack it, and then run this commands:

python setup.py bdist_wheel --xplat
pip install dist\pythonnet-2.4.0.dev0-cp36-cp36m-win64.whl

This is simpler with pip+git, but someone broke this recently: #555

@den-run-ai
Copy link
Contributor

just checked and the master branch works great, but the dtype cannot be extracted:

> #r C:\\Python\\Python35_64b\\lib\\site-packages\\Python.Runtime.DLL
> using Python.Runtime;
> dynamic np; using (Py.GIL()) { np = Py.Import("numpy");};
> using System.Collections.Generic;
> using System.Collections;
> dynamic a = np.array(new List<float> { 1, 2, 3 });
> dynamic b = np.array(new List<float> { 6, 5, 4 }, dtype: np.int32);
> Console.WriteLine(a.dtype);
Cannot implicitly convert type 'void' to 'object'
> a.ToString()
[ 1.  2.  3.]
> b.ToString()
[6 5 4]

@fgiaret
Copy link
Author
fgiaret commented Oct 10, 2017

It works, great! Thank you!

Maybe it's a stupid question, but can I use PythonEngine.Exec or other methods to run python scripts which are defined in a separate file "myscript.py"? I can execute strings of code, but wasn't be able to run scripts yet.

@den-run-ai
Copy link
Contributor

@fgiaret I see you edited your response with additional question. In future please try to add this as another comment, because no one will get this update in email due to github limitations.

Regarding your question - this is possible, have a look at this directory with tests:

https://github.com/pythonnet/pythonnet/blob/master/src/embed_tests/TestPyScope.cs

@fgiaret
Copy link
Author
fgiaret commented Oct 18, 2017

Ok, thank you very much!

@den-run-ai
Copy link
Contributor

@fgiaret I'm closing this issue, but for type conversion error I opened a separate issue:

#563

@den-run-ai
Copy link
Contributor

@fgiaret don't forget to star the repo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0