You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried the solution suggested on #48 , but it is not working. I am using Julia 0.6.2 on Windows with Python 2.7 and the program is
using PyCall
unshift!(PyVector(pyimport("sys")["path"]),"")
@pyimport Leitura_Sistema_REDS as ls
and I get the error message
ERROR: LoadError: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)
The Python package Leitura_Sistema_REDS could not be found by pyimport. Usually this means
that you did not install Leitura_Sistema_REDS in the Python version being used by PyCall.
Adding an empty string to sys.path is not really a good practice. I think the right approach is pushfirst!(PyVector(pyimport("sys")["path"]), @__DIR__). This way, running Julia script works in any directory. This is close to what Python interpreter does when executing a script (it does not add "" to sys.path). Here is an example:
$ cat script.jlusing PyCallpushfirst!(PyVector(pyimport("sys")["path"]), @__DIR__)pyimport("mymodule")[:main]()
$ cat mymodule.pydef main(): import sys print(*sys.path, sep="\n")if __name__ == "__main__": main()
$ cd /
$ julia /PATH/TO/DIR/script.jl/PATH/TO/DIR/usr/lib/python37.zip/usr/lib/python3.7/usr/lib/python3.7/lib-dynload/usr/lib/python3.7/site-packages
$ python /PATH/TO/DIR/mymodule.py # prints the same paths
Of course, pyimport has to be done in __init__ if you are creating a Julia module.
(We probably should add this to README)
MaxandreJ, thautwarm, terasakisatoshi and mjkramer
In the README I think instead of suggesting the command pushfirst!(PyVector(pyimport("sys")["path"]), "") I would have written pushfirst!(PyVector(pyimport("sys")["path"]), "<path_to_be_added>") or something like this. I found myself replacing "path" by the path I wanted to add... I'm sure other people will make the same mistake.
Activity
YP-Ye commentedon Oct 24, 2018
I get the same error. unshift!(PyVector(pyimport("sys")["path"]),"") does not work.
stevengj commentedon Oct 25, 2018
What is your current directory? i.e. what is
pwd()
? Are you sure that you are in the directory with the module that you want?YP-Ye commentedon Oct 25, 2018
Sorry, I found that my problem is caused by a python module named gurobipy. The problem is solved after reinstalling the module.
tkf commentedon Oct 26, 2018
Adding an empty string to
sys.path
is not really a good practice. I think the right approach ispushfirst!(PyVector(pyimport("sys")["path"]), @__DIR__)
. This way, running Julia script works in any directory. This is close to what Python interpreter does when executing a script (it does not add""
tosys.path
). Here is an example:Of course,
pyimport
has to be done in__init__
if you are creating a Julia module.(We probably should add this to README)
MaxandreJ commentedon Nov 6, 2018
In the README I think instead of suggesting the command
pushfirst!(PyVector(pyimport("sys")["path"]), "")
I would have writtenpushfirst!(PyVector(pyimport("sys")["path"]), "<path_to_be_added>")
or something like this. I found myself replacing"path"
by the path I wanted to add... I'm sure other people will make the same mistake.