Skip to content

How to do imports in global scope? #270

Answered by cjdoris
marius311 asked this question in Q&A
Discussion options

You must be logged in to vote

@pyexec always runs in a local scope. I think putting global np at the top of the first call does what you want.

Alternatively pyexec("import numpy as np", @__module__) works in global scope unless you provide a local scope in the 3rd arg.

Btw there is no distinction between single- and multi-line code (unlike PyCall's py"..." macro). You probably want @pyeval for your second call.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by marius311
Comment options

You must be logged in to vote
2 replies
@cjdoris
Comment options

@marius311
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants