Hello, Im trying to import a file with functions and classes written in python.
i have tried using this:
x = pyimport("Models.py")
x = pyimport("Models")
Models.py is in the same directory
and other way i found but nothing is working.
i get the list of directories like PyObject [ '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/p ...] with also the directory im working on. so i think the problem should be here x = pyimport("Models")
Sorry that I can’t really help you then. It may be worthwhile to give some additional information about your installation, like the julia and PyCall versions you are using, the Python version linked by PyCall and whether you have anything else going on that may interfere with package loading (python or julia running in virtual environments, access restrictions or the like).
To narrow it further down, now that we’re sure that Modules.py is where it’s supposed to be, can you try accessing the path you pushed to pyimport("sys")."path" from withing Python (via PyCall, not a separate instance) and see if Modules.py is visible there?
The following little example works for me. Maybe this helps you
Code of Python custom_print function in test.py:
the file is stored in the path, which I have specified under the environment variable PYTHONPATH (it should also work with the path, which you push with push!(pyimport("sys")."path", "/path/of/directory") ).
Commands in julia to call python function
test = pyimport("test")
thank you both @FPGro@Volker , i always thought the problem was in the pyimport but it would have not worked anyway even in python.
i tried running the example you gave me and they both worked so the i figured out the problem was in the import of the file.
import Layers //in another file.py
the Layer.py to import in the Models.py was in another directory.
but i always just read this part in the error window of julia:
The Python package Models could not be imported by pyimport. Usually this means
that you did not install Models in the Python version being used by PyCall