我正在尝试在Google colab上永久安装库。所以我先运行这段代码:
import os, sys
from google.colab import drive
drive.mount('/content/drive', force_remount = True)
my_path = '/content/notebooks'
os.symlink('/content/drive/My Drive/Colab Notebooks/my_env', my_path)
sys.path.insert(0, my_path)
上面的代码没有错误。
但是,当我运行下面的代码时,出现了错误:
!pip install --target=$my_path jdc
Collecting jdc
Downloading https://files.pythonhosted.org/packages/5a/cb/9afea749985eef20f3160e8826a531c7502e40c35a038dfe49b67726e9a0/jdc-0.0.9-py2.py3-none-any.whl
Installing collected packages: jdc
Successfully installed jdc-0.0.9
ERROR: Exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/shutil.py", line 550, in move
os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-target-21y8mx4d/lib/python/jdc' -> '/content/notebooks/jdc'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 153, in _main
status = self.run(options, args)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 505, in run
options.target_dir, target_temp_dir, options.upgrade
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 563, in _handle_target_dir
target_item_dir
File "/usr/lib/python3.6/shutil.py", line 561, in move
symlinks=True)
File "/usr/lib/python3.6/shutil.py", line 321, in copytree
os.makedirs(dst)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/content/notebooks/jdc'
有没有办法解决这个问题?
答案 0 :(得分:0)
首先将目录定向到您要在其中安装库的目录:
%cd "/path/to/your/directory"
然后使用```pip``安装
pip install jdc