Giter Club home page Giter Club logo

cython-book's People

Contributors

philberty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cython-book's Issues

Compiling the AddFunction example (chapter 1) with distutils

Hey,

So I have just started using Cython, but I am having trouble running the "ownmodule" example with distutils.

If I run make, I can get the right result, but I really want to use distutils, for simplicity.

This is what my setup.py looks like:

from distutils.core import setup, Extension
from Cython.Distutils import build_ext

modules = [
Extension("PyAddFunction", sources=["PyAddFunction.pyx"])
]

setup(
cmdclass={'build_ext': build_ext},
ext_modules = modules
)

and it compiles with no error.

But when I try to import the module, I get the following error:

from PyAddFunction import Add

ImportError: dlopen(/Users/PycharmProjects/project/PyAddFunction.so, 2): Symbol not found: _AddFunction
Referenced from: /Users/PycharmProjects/project/PyAddFunction.so
Expected in: flat namespace
in /Users/PycharmProjects/project/PyAddFunction.so

How can I solve this error?
Thanks in advance,
EPiress

(How) could I use cython to return Session, Window and Pane info from tmux?

I am happy I've found your book, I am a few chapters in, but the foundations / tools of C is still over my head.

I have a project at https://github.com/tony/tmuxp that's kind of like https://github.com/remiprev/teamocil / https://github.com/aziz/tmuxinator for python.

tmuxp has some cool things to it, it abstracts out the CLI commands into a python ORM. There is the Server object, which can be set to a socket_name and socket_path, and then hold relationships with Session, Window and Pane.

The issue is, I'd like instances of these objects to always have access to the freshest data.

Since version 1.8, Sessions, Windows and Panes all have unique ID's. Creating a new window with new-window can return the new window_id, which tmuxp can make a new Window object out of.

In addition, list-sessions, list-windows, list-panes allow -F to provide rich details about the current tmux objects on the server.

At present, all Session, Window, Pane objects report to Server when their details are looked up, and Server will do a subprocess.call to get the latest info. This is expensive. Both for building tmux sessions, and for getting information about current details from tmux.

What I'm trying to see how I could get bypass using so many subprocess calls. One option would be to have an instance of tmux -C in control mode. Beyond this, I don't know how to technically implement these at this point:

  • tmux uses libevent. Does that mean a python library can create a client connection without interfacing with C and pull current session, window, pane without requiring cython at all? Could something like struct have something to do with parsing the data?
  • What would it take for cython to have the equivalent of doing a shell command to tmux? Like when I do subprocess.call to tmux list-sessions -F"{alltheseformats}", is there a way to hook in to cmd and get info back?

From what I understand, getting any info from tmux requires having a client instance, even temporarily.

  • Would there be a way to receive the struct of a Session, Window, Pane tree in tmux and have it returned as a python object/dictionary?
  • If there isn't a direct way to do that, is cython able to create the object / dict right there for speed and performance?

Now more than ever I feel helpless for not having a firm foundational understanding C and its tools. I think the only thing short of creating a pure python multiplexer (https://github.com/saitoha/canossa looks very promising) is having something like tmuxp able to control sessions.

Can you help me? I know your pressed for time, anything could help at this point.

Chapter 1 HelloWorld

Hi,
I am trying to run the HelloWorld example I have that error "ImportError: dynamic module does not define init function (PyInit_helloworld)".

Could you tell me how to fix that please ?

Chapter1 Helloworld for Mac and Python installed with homebrew

Hi
I was trying your 1st example (Chapter 1, Helloworld), and I get the following message

Python 2.7.11 (default, Jan 22 2016, 16:30:50)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import helloworld
Fatal Python error: PyThreadState_Get: no current thread
fish: 'python' terminated by signal SIGABRT (Abort)

After some googling, I've discovered that the error comes from the fact that I am using, on my mac, several Python versions (one from Apple, and the others installed with the homebrew system, as described here for example)

The command otool -L helloworld.so returns

helloworld.so (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.17.0)

indicating that the helloworld.so was linked with the Python 2.7.5 (the original apple version), that is not the active version (Python 2.7.11, installed with homebrew).

So, I changed a little bit the Makefile to

all:
    cython -2 -o helloworld.c helloworld.pyx
    gcc -g -O2 -fpic -c helloworld.c -o helloworld.o `python-config --cflags`
    gcc -g -O2 -shared -o helloworld.so helloworld.o `python-config --ldflags`

(--ldflagsinstead of --libs) and everything is fine, now.

About Chapter1

how could I if I first compile c and generate .so and with .h files
for example for the chapter 1:
gcc -g -O2 -fpic -c mycode.c -o mycode.o
gcc -g -O2 -shared -o mycode.so mycode.o

if I don't have any mycode.c and mycode.o files.
how could I use Cython to compile the .pyx.
Thanks.

Issue with linking on Mac

Hi! I'm trying to make chapter2 / server3-4 and have problem with linking.
Why could this happen? How to fix?

(py275)MacBook-Air-Ivan:cython-book (master) $ cd ./chapter2/messaging-server/server4                           
(py275)MacBook-Air-Ivan:server4 (master) $ make
cython -2 -o pyserver.c pyserver.pyx
gcc -g -O2 -Wall -fpic -c server.c -o server.o
gcc -g -O2 -Wall -fpic -c pyserver.c -o pyserver.o `python-config --cflags`
pyserver.c:2157:28: warning: unused function '__Pyx_PyObject_AsString' [-Wunused-function]
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
                           ^
pyserver.c:2154:32: warning: unused function '__Pyx_PyUnicode_FromString' [-Wunused-function]
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
                               ^
pyserver.c:298:29: warning: unused function '__Pyx_Py_UNICODE_strlen' [-Wunused-function]
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
                            ^
pyserver.c:2269:33: warning: unused function '__Pyx_PyIndex_AsSsize_t' [-Wunused-function]
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
                                ^
pyserver.c:2294:33: warning: unused function '__Pyx_PyInt_FromSize_t' [-Wunused-function]
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
                                ^
pyserver.c:1988:32: warning: unused function '__Pyx_PyInt_From_long' [-Wunused-function]
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
                               ^
pyserver.c:2014:27: warning: function '__Pyx_PyInt_As_long' is not needed and will not be emitted [-Wunneeded-internal-declaration]
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
                          ^
7 warnings generated.
pyserver.c:2157:28: warning: unused function '__Pyx_PyObject_AsString' [-Wunused-function]
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
                           ^
pyserver.c:2154:32: warning: unused function '__Pyx_PyUnicode_FromString' [-Wunused-function]
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
                               ^
pyserver.c:298:29: warning: unused function '__Pyx_Py_UNICODE_strlen' [-Wunused-function]
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
                            ^
pyserver.c:2269:33: warning: unused function '__Pyx_PyIndex_AsSsize_t' [-Wunused-function]
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
                                ^
pyserver.c:2294:33: warning: unused function '__Pyx_PyInt_FromSize_t' [-Wunused-function]
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
                                ^
pyserver.c:1988:32: warning: unused function '__Pyx_PyInt_From_long' [-Wunused-function]
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
                               ^
pyserver.c:2014:27: warning: function '__Pyx_PyInt_As_long' is not needed and will not be emitted [-Wunneeded-internal-declaration]
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
                          ^
7 warnings generated.
gcc -g -O2 -shared -o pyserver.so server.o pyserver.o -levent
Undefined symbols for architecture x86_64:
  "_PyCFunction_NewEx", referenced from:
      _initpyserver in pyserver.o
  "_PyCFunction_Type", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
  "_PyCode_New", referenced from:
      _initpyserver in pyserver.o
      ___Pyx_AddTraceback in pyserver.o
  "_PyDict_GetItem", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyDict_New", referenced from:
      _initpyserver in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyDict_SetItem", referenced from:
      _initpyserver in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyErr_ExceptionMatches", referenced from:
      _initpyserver in pyserver.o
  "_PyErr_Format", referenced from:
      _initpyserver in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
      ___Pyx_PyInt_As_int in pyserver.o
  "_PyErr_Occurred", referenced from:
      _initpyserver in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
      ___Pyx_PyInt_As_int in pyserver.o
      ...
  "_PyErr_SetString", referenced from:
      _initpyserver in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
      ___Pyx_PyInt_As_int in pyserver.o
      ...
  "_PyErr_WarnEx", referenced from:
      _initpyserver in pyserver.o
  "_PyErr_WriteUnraisable", referenced from:
      ___Pyx_WriteUnraisable in pyserver.o
  "_PyExc_AttributeError", referenced from:
      _initpyserver in pyserver.o
  "_PyExc_ImportError", referenced from:
      _initpyserver in pyserver.o
  "_PyExc_NameError", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyExc_OverflowError", referenced from:
      ___Pyx_PyInt_As_int in pyserver.o
  "_PyExc_RuntimeError", referenced from:
      ___Pyx_PrintOne in pyserver.o
  "_PyExc_SystemError", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyExc_TypeError", referenced from:
      ___Pyx_PyInt_As_int in pyserver.o
  "_PyFile_SoftSpace", referenced from:
      ___Pyx_PrintOne in pyserver.o
  "_PyFile_WriteObject", referenced from:
      ___Pyx_PrintOne in pyserver.o
  "_PyFile_WriteString", referenced from:
      ___Pyx_PrintOne in pyserver.o
  "_PyFrame_New", referenced from:
      ___Pyx_AddTraceback in pyserver.o
  "_PyImport_AddModule", referenced from:
      _initpyserver in pyserver.o
  "_PyInt_FromLong", referenced from:
      _initpyserver in pyserver.o
  "_PyList_New", referenced from:
      _initpyserver in pyserver.o
  "_PyLong_AsLong", referenced from:
      ___Pyx_PyInt_As_int in pyserver.o
  "_PyMem_Malloc", referenced from:
      ___Pyx_AddTraceback in pyserver.o
  "_PyMem_Realloc", referenced from:
      ___Pyx_AddTraceback in pyserver.o
  "_PyMethod_Type", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
  "_PyModule_GetDict", referenced from:
      _initpyserver in pyserver.o
  "_PyNumber_Int", referenced from:
      ___Pyx_PyInt_As_int in pyserver.o
  "_PyNumber_Long", referenced from:
      ___Pyx_PyInt_As_int in pyserver.o
  "_PyOS_snprintf", referenced from:
      _initpyserver in pyserver.o
  "_PyObject_Call", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyObject_CallFunctionObjArgs", referenced from:
      _initpyserver in pyserver.o
  "_PyObject_GetAttr", referenced from:
      _initpyserver in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyObject_IsTrue", referenced from:
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyObject_SetAttrString", referenced from:
      _initpyserver in pyserver.o
  "_PyString_FromFormat", referenced from:
      ___Pyx_AddTraceback in pyserver.o
  "_PyString_FromString", referenced from:
      ___Pyx_AddTraceback in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
      ___Pyx_WriteUnraisable in pyserver.o
  "_PyString_FromStringAndSize", referenced from:
      _initpyserver in pyserver.o
  "_PyString_InternFromString", referenced from:
      _initpyserver in pyserver.o
  "_PySys_GetObject", referenced from:
      ___Pyx_PrintOne in pyserver.o
  "_PyTraceBack_Here", referenced from:
      ___Pyx_AddTraceback in pyserver.o
  "_PyTuple_New", referenced from:
      _initpyserver in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "_PyTuple_Pack", referenced from:
      _initpyserver in pyserver.o
  "_PyUnicodeUCS2_DecodeUTF8", referenced from:
      _initpyserver in pyserver.o
  "_Py_GetVersion", referenced from:
      _initpyserver in pyserver.o
  "_Py_InitModule4_64", referenced from:
      _initpyserver in pyserver.o
  "__PyThreadState_Current", referenced from:
      ___Pyx_AddTraceback in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
      ___Pyx_WriteUnraisable in pyserver.o
      ...
  "__Py_CheckRecursionLimit", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "__Py_CheckRecursiveCall", referenced from:
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___Pyx_PyObject_CallOneArg in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "__Py_NoneStruct", referenced from:
      _initpyserver in pyserver.o
      ___pyx_pw_8pyserver_1pyinit_server in pyserver.o
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
      ___Pyx_WriteUnraisable in pyserver.o
  "__Py_TrueStruct", referenced from:
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
  "__Py_ZeroStruct", referenced from:
      ___pyx_f_8pyserver_pyconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pydisconnect_callback in pyserver.o
      ___pyx_f_8pyserver_pyread_callback in pyserver.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.