本文介绍了在Google Colab中使用IJulia时如何安装Google驱动器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让Julia在合作实验室中工作.我想像使用IJulia时在IPython中一样将gdrive挂载到colab.在ipython中,我可以按照以下步骤进行操作:
I am trying to get Julia working in colab. I want to mount gdrive to colab just like in IPython when using IJulia. In ipython I can do it as follows:
from google.colab import drive
drive.mount('/content/gdrive')
我尝试了以下操作:
using PyCall
clb = pyimport("google")
clb.colab.drive.mount("/content/gdrive")
------------------------------------------------------------------------------------
Warning: Password input may be echoed.
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=...
Enter your authorization code:
PyError ($(Expr(:escape, :(ccall(#= /root/.julia/packages/PyCall/ttONZ/src/pyfncall.jl:44 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'EOFError'>
EOFError()
File "/usr/local/lib/python3.6/dist-packages/google/colab/drive.py", line 234, in mount
fifo_file.write(_getpass.getpass(auth_prompt) + '\n')
File "/usr/lib/python3.6/getpass.py", line 91, in unix_getpass
passwd = fallback_getpass(prompt, stream)
File "/usr/lib/python3.6/getpass.py", line 126, in fallback_getpass
return _raw_input(prompt, stream)
File "/usr/lib/python3.6/getpass.py", line 148, in _raw_input
raise EOFError
Stacktrace:
[1] pyerr_check at /root/.julia/packages/PyCall/ttONZ/src/exception.jl:60 [inlined]
[2] pyerr_check at /root/.julia/packages/PyCall/ttONZ/src/exception.jl:64 [inlined]
[3] macro expansion at /root/.julia/packages/PyCall/ttONZ/src/exception.jl:84 [inlined]
[4] __pycall!(::PyObject, ::Ptr{PyCall.PyObject_struct}, ::PyObject, ::Ptr{Nothing}) at /root/.julia/packages/PyCall/ttONZ/src/pyfncall.jl:44
[5] _pycall!(::PyObject, ::PyObject, ::Tuple{String}, ::Int64, ::Ptr{Nothing}) at /root/.julia/packages/PyCall/ttONZ/src/pyfncall.jl:29
[6] #call#111 at /root/.julia/packages/PyCall/ttONZ/src/pyfncall.jl:11 [inlined]
[7] (::PyObject)(::String) at /root/.julia/packages/PyCall/ttONZ/src/pyfncall.jl:89
[8] top-level scope at In[9]:3
using PyCall
py"""
from google.colab import drive
drive.mount('/content/gdrive')
"""
cd("/content/gdrive/My\ Drive")
------------------------------------------------------------------------------------
Warning: Password input may be echoed.
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=...
Enter your authorization code:
PyError ($(Expr(:escape, :(ccall(#= /root/.julia/packages/PyCall/ttONZ/src/pyeval.jl:39 =# @pysym(:PyEval_EvalCode), PyPtr, (PyPtr, PyPtr, PyPtr), o, globals, locals))))) <class 'EOFError'>
EOFError()
File "/root/.julia/packages/PyCall/ttONZ/src/pyeval.jl", line 2, in <module>
const Py_file_input = 257
File "/usr/local/lib/python3.6/dist-packages/google/colab/drive.py", line 234, in mount
fifo_file.write(_getpass.getpass(auth_prompt) + '\n')
File "/usr/lib/python3.6/getpass.py", line 91, in unix_getpass
passwd = fallback_getpass(prompt, stream)
File "/usr/lib/python3.6/getpass.py", line 126, in fallback_getpass
return _raw_input(prompt, stream)
File "/usr/lib/python3.6/getpass.py", line 148, in _raw_input
raise EOFError
Stacktrace:
[1] pyerr_check at /root/.julia/packages/PyCall/ttONZ/src/exception.jl:60 [inlined]
[2] pyerr_check at /root/.julia/packages/PyCall/ttONZ/src/exception.jl:64 [inlined]
[3] macro expansion at /root/.julia/packages/PyCall/ttONZ/src/exception.jl:84 [inlined]
[4] pyeval_(::String, ::PyDict{String,PyObject,true}, ::PyDict{String,PyObject,true}, ::Int64, ::String) at /root/.julia/packages/PyCall/ttONZ/src/pyeval.jl:39
[5] top-level scope at /root/.julia/packages/PyCall/ttONZ/src/pyeval.jl:232
[6] top-level scope at In[10]:2
两个都不起作用.
推荐答案
实现此目的的一种方法是,在默认情况下Runtime type
是Python时,通过运行以下命令,在安装Julia之前先安装Google驱动器:
One way to achieve this is to mount google drive before installing Julia, when default Runtime type
is Python by running:
from google.colab import drive
drive.mount('/content/gdrive')
这样,即使将Runtime type
更改为Julia之后,Google驱动器仍会挂载,直到您更改Hardware acceleration
或会话丢失为止.
That way, even after Runtime type
is changed to Julia, google drive remains mounted until you change Hardware acceleration
or session is lost.
这篇关于在Google Colab中使用IJulia时如何安装Google驱动器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!