cython consults parent directory as package name, fails with "is not a valid module name"

658 views
Skip to first unread message

Gojo Git

unread,
Jun 25, 2015, 2:44:54 AM6/25/15
to cython...@googlegroups.com
However I try to invoke cython compilation, it's reaching one parent directory higher than I want it to, where it finds an objectionable package name. (I think it doesn't like the internal dash.) I don't see anything in the project setup that mentions that name, or directs cython to consider that level the root/package container.

My kludgey workaround has been to rename the directory for each compilation – then name it back afterwards. (The dash-convention, introduced by other tools, works for everything else.) But that's now getting the in the way of cross- cimports among my PYX files. 

Tthere's got to be a way to force cython's idea of the root/project-name, right? (Is it imputing it as always being N dirs up from extension source, or setup.py, or something?)

Here's a transcript of the frustration:

(gensim_cenv)ubuntu@ubuntu14:~/src/gensim-develop$ ls gensim/models/*pyx

gensim/models/doc2vec_inner.pyx  gensim/models/word2vec_inner.pyx

(gensim_cenv)ubuntu@ubuntu14:~/src/gensim-develop$ cython gensim/models/word2vec_inner.pyx 


Error compiling Cython file:

------------------------------------------------------------

...

#!/usr/bin/env cython

^

------------------------------------------------------------


gensim/models/word2vec_inner.pyx:1:0: 'gensim-develop.gensim.models.word2vec_inner' is not a valid module name

(gensim_cenv)ubuntu@ubuntu14:~/src/gensim-develop$ cd ..

(gensim_cenv)ubuntu@ubuntu14:~/src$ mv gensim-develop trunk

(gensim_cenv)ubuntu@ubuntu14:~/src$ cd trunk

(gensim_cenv)ubuntu@ubuntu14:~/src/trunk$ cython gensim/models/word2vec_inner.pyx 

(gensim_cenv)ubuntu@ubuntu14:~/src/trunk$ cd ../

(gensim_cenv)ubuntu@ubuntu14:~/src$ mv trunk gensim-develop

(gensim_cenv)ubuntu@ubuntu14:~/src$ cd gensim-develop

(gensim_cenv)ubuntu@ubuntu14:~/src/gensim-develop$  # then I build_ext/install


You can see the whole project setup at <https://github.com/piskvorky/gensim>. The project layout seems to work OK in automated builds and pip/package installs... but I can't figure what's wrong with my one-off cython invocations. I've tried from many working-directories, with alternate '-w' arguments, various edits to paths in setup.py, etc with no luck 


Any ideas what I'm missing?


- Gordon 

Stefan Behnel

unread,
Jun 25, 2015, 2:48:28 AM6/25/15
to cython...@googlegroups.com
Gojo Git schrieb am 25.06.2015 um 08:14:
> However I try to invoke cython compilation, it's reaching one parent
> directory higher than I want it to, where it finds an objectionable package
> name. (I think it doesn't like the internal dash.) I don't see anything in
> the project setup that mentions that name, or directs cython to consider
> that level the root/package container.
>
> gensim/models/word2vec_inner.pyx:1:0:
> 'gensim-develop.gensim.models.word2vec_inner' is not a valid module name
>
> You can see the whole project setup at
> <https://github.com/piskvorky/gensim>.

You have an "__init__.py" file in your project root directory, which turns
it into a package. Just delete that file.

Stefan

Gojo Git

unread,
Jun 25, 2015, 12:06:42 PM6/25/15
to cython...@googlegroups.com, stef...@behnel.de
Thanks! Without the stray __init__.py, compilation works as expected, and project-relative cimports too. 

(Now, to figure out why the strangely-placed __init__.py landed there years ago...)

- Gordon
Reply all
Reply to author
Forward
0 new messages