0

I try to import gym module of python inside julia by using PyCall.jl library.

To make it, I applied the followings:

$ julia
julia>  using PyCall
julia>  gym = pyimport("gym")
ERROR: PyError (:PyImport_ImportModule) <type 'exceptions.ImportError'>
ImportError('No module named gym',)

On the otherhand, if I directly try to import it within python, I was able to do that without any error

$ python
>>> import gym
>>> # no error here

Finally, to test whether PyCall package have problem or not, I tried to call another python module "sys" with the same way. There wasn't any problem with that:

  $ julia
    julia>  using PyCall
    julia>  sys = pyimport("sys")
    PyObject <module 'sys' (built-in)>

Is there anyone who could have any idea about my problem?

Here is my python version :

$python
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul  2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>>
zwlayer
  • 1,752
  • 1
  • 18
  • 41
  • perhaps it has something to do with python2 vs python3 package, or installation of "gym" in an unusual place? How was "gym" installed? (it is not in the standard ubuntu repository for one) – Tasos Papastylianou Jan 26 '17 at 15:41
  • Possibly [related](https://github.com/JuliaPy/PyCall.jl/issues/48) – o-90 Jan 26 '17 at 16:13
  • Thanks for all. I've found the solution. Shortly. We need to give the path of python environment inside the Julia before building Pycall package. I'll write the long answer asap. – zwlayer Jan 26 '17 at 18:09

1 Answers1

1

It looks like the version of Python being used by PyCall is different from the version which you installed gym with.

To change the version of Python which PyCall is using, you can rebuild the package with a different Python executable path.

julia> ENV["PYTHON"] = "/usr/bin/python"  # path to your Python executable
"/usr/bin/python"

julia> Pkg.build("PyCall")
INFO: Building Conda
INFO: Building PyCall
INFO: PyCall is using /usr/bin/python (Python 2.7.12) at /usr/bin/python, libpython = libpython2.7
INFO: /home/user/.julia/v0.5/PyCall/deps/deps.jl has been updated
INFO: /home/user/.julia/v0.5/PyCall/deps/PYTHON has been updated

I assume that your Python executable is located at /usr/bin/python. To find its path on UNIX, you can run which python.

~$ which python
/usr/bin/python
Harrison Grodin
  • 2,253
  • 2
  • 19
  • 30