Skip to content

Importing local modules #70

Closed
Closed

Description

@boriskaus

Thanks, this appears to be a very useful package which would solve many compatibility problems between windows, linux etc.

One thing I am wondering is how to import a local module. In PyCall this would be done as:

const pymodule = PyNULL()
pushfirst!(PyVector(pyimport("sys")["path"]), (@__DIR__)*"/dir_relative_to_src") 
copy!(pymodule, pyimport("mylocalmodule"))

Help on how to do this in PythonCall would be highly appreciated!

Activity

  1. cjdoris commented on Nov 17, 2021

    @cjdoris
    Member

    Glad you like it!

    The equivalent in PythonCall is:

    const pymodule = PythonCall.pynew()
    pyimport("sys").path.append("some/path")
    PythonCall.pycopy!(pymodule, pyimport("mylocalmodule"))
    
  2. boriskaus commented on Nov 17, 2021

    @boriskaus
    Author

    Thanks, that works! See https://github.com/JuliaGeodynamics/geomIO. Next up is figuring out why CI fails on windows, but works on Mac/Linux.

  3. kleinschmidt commented on Aug 15, 2024

    @kleinschmidt

    I'm following this pattern and getting occasional segfaults when I try to access the imported module (the one that I pycopy!ed). Do I need to do something like GC protect that pointer so it doesn't get GCed? Can I even do that on the julia side or do I need to do it on the python side somehow?

  4. kleinschmidt commented on Aug 15, 2024

    @kleinschmidt

    I get the same behavior FWIW when using Ref{Py} to store the imported module as well...

  5. kleinschmidt commented on Aug 16, 2024

    @kleinschmidt

    Wow and when I pyimport the module afresh each time before referring to it. I suspect this may be something specific to my module and how I'm using it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions