Skip to content
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

Pyximport fails to compile other modules after __init__ #2977

Open
Keithcat1 opened this issue May 31, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Keithcat1
Copy link

commented May 31, 2019

I'm not sure if this goes here, but I found no other place to put it.
So, with pyximport.install(pyximport=True) in my sitecustomize.py, pyximport, when Cythonizing a package, will first Cythonize __init__, but then tries to Cythonize other modules from the same package.
This causes an error, presumably because it's now using __init__.pyd that it just compiled as a starting location to import other modules, and of course nothing has been Cythonized yet?
Would it be possible to Cythonize __init__ last, so everything else is already Cythonized first?

@scoder

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

pyximport is an import hook that compiles modules on the fly while importing them. Meaning, it needs to compile a module before it gets imported, and the __init__.py[xd] module of a package must be imported before the modules that the package contains.

What kind of error do you get?

@Keithcat1

This comment has been minimized.

Copy link
Author

commented Jun 1, 2019

When trying to compile some modules from the Crypto package that get loaded by my code:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import pack
pack.c
pack.obj : warning LNK4197: export 'PyInit_pack' specified multiple times; using
first specification
Creating library C:\Users\You.pyxbld\temp.win-amd64-3.7\Release\Users\You.p
yxbld\temp.win-amd64-3.7\Release\pyrex\pack.cp37-win_amd64.lib and object C:\Use
rs\You.pyxbld\temp.win-amd64-3.7\Release\Users\You.pyxbld\temp.win-amd64-3.7\R
elease\pyrex\pack.cp37-win_amd64.exp
Generating code
Finished generating code
init.c
init.obj : warning LNK4197: export 'PyInit___init__' specified multiple time
s; using first specification
Creating library C:\Users\You.pyxbld\temp.win-amd64-3.7\Release\Users\You.p
yxbld\temp.win-amd64-3.7\Release\pyrex\Crypto_init_.cp37-win_amd64.lib and ob
ject C:\Users\You.pyxbld\temp.win-amd64-3.7\Release\Users\You.pyxbld\temp.win-
amd64-3.7\Release\pyrex\Crypto_init_.cp37-win_amd64.exp
Generating code
Finished generating code
Traceback (most recent call last):
File "C:\python37\lib\site-packages\pyximport\pyximport.py", line 216, in load
_module
mod = imp.load_dynamic(name, so_path)
File "C:\python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
File "pack.py", line 4, in init pack
from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto.Cipher'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "C:\python37\lib\site-packages\pyximport\pyximport.py", line 423, in load
_module
return load_module(fullname, source_path, so_path=so_path, is_package=is_pac
kage)
File "C:\python37\lib\site-packages\pyximport\pyximport.py", line 231, in load
_module
raise exc.with_traceback(tb)
File "C:\python37\lib\site-packages\pyximport\pyximport.py", line 216, in load
_module
mod = imp.load_dynamic(name, so_path)
File "C:\python37\lib\imp.py", line 342, in load_dynamic
return _load(spec)
File "pack.py", line 4, in init pack
from Crypto.Cipher import AES
ImportError: Building module pack failed: ["ModuleNotFoundError: No module named
'Crypto.Cipher'\n"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.