运行 从 Github 安装和导入时出错

Error when running install and import from Github

我正在使用python;协作。 我尝试从“github.com/jleinonen/keras-fid”安装包以导入 fid。我第一次使用:

!pip install git+git://github.com/jleinonen/keras-fid.git  

但是我得到了错误;

Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

所以我用了:!git clone 我使用

从 Github 安装包
!git clone https://github.com/jleinonen/keras-fid.git 

不如尝试导入模块 但是,我不确定,但我认为因为包名包含“-”,所以我得到了

SyntaxError: invalid syntax

如何从这个包中导入模块

- 是一条红鲱鱼。问题是 Github 回购不能 pip installed 因为它不包含 setup.py.

当您 git cloned 代码时,您只需将其复制到您的环境中。它仍然不是简单的安装...虽然你现在可以做的是将克隆的目录添加到你的 PYTHONPATH,或者将文件 fid.py 从里面复制到你的 [=17] 上已经存在的某个地方=].

快速演示:

bash$ python -c "import fid"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'fid'

bash$ git clone https://github.com/jleinonen/keras-fid.git 
Cloning into 'keras-fid'...
remote: Enumerating objects: 12, done.
remote: Total 12 (delta 0), reused 0 (delta 0), pack-reused 12
Unpacking objects: 100% (12/12), done.

现在,我们有一个本地克隆,但如您所见,它尚未安装:

bash$ python -c "import fid"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'fid'

您可以在 PYTHONPATH 中添加目录名称(其中确实包含一个连字符,但在这里没有问题),然后它就可以工作了……除了代码包含语法错误。

bash$ PYTHONPATH=${PYTHONPATH+$PYTHONPATH:}`pwd`/keras-fid python -c "import fid"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/keras-fid/fid.py", line 134
    def __init__(self, generator, image_range=, 
                                              ^

我不知道代码应该做什么,我对 Keras 或 Google Colab 一无所知;但是将其更改为逗号前没有等号的 image_range, 至少可以让我绕过这个错误。

how to add the path to PYTHONPATH in google colab 似乎有关于如何在 Google Colab 中做类似事情的提示。