从 GitHub 安装 Python 库完成 4 种方法(未成功)

Installing Python Libraries from GitHub done 4 Ways (unsuccessfully)

我必须安装一个名为 sonLib from the author's Git repo. It is a dependency of jobTree, which I will also later need. Trouble is it won't install. I've tried 4 methods listed below. Methods 1) and 3) both have the same error which is addressed here, but I could not find an analgous error in his setup.py 的 python package/library/module。这些错误中是否存在最容易处理的错误之一?是否有另一种方法来安装这个(和 jobTree),以便我可以通过位于 /usr/bin/python2.7 中的 python 导入它?

方法一

git clone https://github.com/benedictpaten/sonLib.git
cd /sonLib
sudo python2.7 setup.py install

错误:

running install
running bdist_egg
running egg_info
creating sonLib.egg-info
writing sonLib.egg-info/PKG-INFO
writing top-level names to sonLib.egg-info/top_level.txt
writing dependency_links to sonLib.egg-info/dependency_links.txt
writing sonLib.egg-info/PKG-INFO
writing top-level names to sonLib.egg-info/top_level.txt
writing dependency_links to sonLib.egg-info/dependency_links.txt
writing manifest file 'sonLib.egg-info/SOURCES.txt'
error: package directory 'sonLib' does not exist

方法二

sudo pip install -e git://github.com/benedictpaten/sonLib.git

错误:

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File "/usr/local/lib/python3.3/dist-packages/setuptools-5.7-py3.3.egg/pkg_resources.py", line 356, in load_entry_point
    def has_metadata(name):
  File "/usr/local/lib/python3.3/dist-packages/setuptools-5.7-py3.3.egg/pkg_resources.py", line 2472, in load_entry_point
    Split environment marker, add == prefix to version specifiers as
  File "/usr/local/lib/python3.3/dist-packages/setuptools-5.7-py3.3.egg/pkg_resources.py", line 2186, in load
    #@property
ImportError: No module named 'pip'

方法三

sudo pip install git+https://github.com/benedictpaten/sonLib.git

错误:

writing manifest file 'pip-egg-info/sonLib.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
error: package directory 'sonLib' does not exist
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-zbppc3-build
Storing complete log in /home/tjm/.pip/pip.log

方法四

来自相关的 sonLib 安装 post on SO

cd /usr/local/lib/python2.7/site-packages/sonLib
sudo git clone https://github.com/benedictpaten/sonLib.git
sudo make all
make test

错误:

make[1]: Entering directory `/usr/local/lib/python2.7/site-packages/sonLib/C'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/usr/local/lib/python2.7/site-packages/sonLib/C'
PYTHONPATH=.. PATH=../../bin:$PATH python allTests.py --testLength=SHORT --logLevel=CRITICAL
Traceback (most recent call last):
  File "allTests.py", line 8, in <module>
    import bioioTest
  File "/usr/local/lib/python2.7/site-packages/sonLib/bioioTest.py", line 69
    print "Got %s levels, %s fileNo and %s maxTempFiles" % (levels, fileNo, maxTempFiles)
                                                       ^
SyntaxError: invalid syntax
make: *** [test] Error 1

您使用的 pip-install-command-syntax 可能有误,在 https://pip.pypa.io/en/latest/reference/pip_install.html#git 之后应该是:

pip install -e git+https://github.com/benedictpaten/sonLib.git#egg=sonLib

"No module named 'pip'" 告诉您当前 Python-解释器没有可用的 pip。如您的示例所示,您正在使用多个 Python 版本。您使用 Python-2.7 安装了 sonLib,然后尝试使用 Python-3.3 的 pip。对于防弹方式,使用 Python-2.7 的 virtenv 并执行:

$ virtenv yourVirtualEnv
$ cd yourVirtualEnv
$ . bin/activate

virtenv 将一路安装 pip,激活它可确保您在几乎不输入 pip 的情况下就可以在命令行中使用它的 pip。完成后,再次停用virtualenv,就是:

$ deactivate

无论如何,激活不是永久性的,当您的 shell-session 结束时,它也会消失。 或者将路径添加到您的 .bashrc,如果您希望它永久成为您的默认 pip。