【问题标题】:Error when trying to install library permanently on google colab尝试在 google colab 上永久安装库时出错
【发布时间】:2020-12-06 10:34:15
【问题描述】:

我正在尝试在 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'

有没有办法解决这个问题?

【问题讨论】:

    标签: python-3.x installation pip google-colaboratory


    【解决方案1】:

    首先定位您要安装库的目录,如下所示:

    %cd "/path/to/your/directory"

    然后使用 ```pip` 安装:

    pip install jdc

    【讨论】:

      猜你喜欢
      • 2021-08-23
      • 1970-01-01
      • 2019-08-10
      • 2019-11-02
      • 2022-11-13
      • 2019-08-09
      • 2023-01-07
      • 2021-08-29
      相关资源
      最近更新 更多