没有名为sh的模块。

5
我安装了原生Python的sh,并开始使用命令进行安装:
$ pip install sh
  Collecting sh
  Could not fetch URL https://pypi.python.org/simple/sh/: There was a problem confirming the ssl 
  certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
  Could not find a version that satisfies the requirement sh (from versions: )
  No matching distribution found for sh

如果上述方法失败,我会下载 sh-1.12.14-py2.py3-none-any.whl 并进行本地安装:

$ pip install
/Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl
Requirement
'/Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl' looks
like a filename, but the file does not exist
Processing ./Downloads/sh-1.12.14-py2.py3-none-any.whl
Exception: 

Traceback (most recent call last):
   File
"/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py",
line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py",
line 299, in run
requirement_set.prepare_files(finder) File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 370, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py",
line 587, in _prepare_file<br/>
session=self.session, hashes=hashes)  File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/download.py",
line 798, in unpack_url
unpack_file_url(link, location, download_dir, hashes=hashes)
File
"/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/download.py",
line 705, in unpack_file_url
unpack_file(from_path, location, content_type, link)
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py",
line 599, in unpack_file
flatten=not filename.endswith('.whl')
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py",
line 482, in unzip_file
zipfp = open(filename, 'rb')
IOError: [Errno 2] No such file or directory:
'/Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl'

这个路径是正确的。它确实存在:
$ cd /Users/zhangkuixun/Downloads/
$ ls
...
sh-1.12.14-py2.py3-none-any.whl

我该如何安装SH并且引用它?现在引用失败了:
$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sh
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sh
>>> 

1
pypi.python.org 真的在使用 TLSV1 吗?我几乎怀疑你是否受到了中间人攻击... - Charles Duffy
实际上,当我自己查看它时(openssl s_client -connect pypi.python.org:443),他们正在使用TLSv1.2。您能否在此提供您获取该站点的SSL证书指纹,以便我们可以检查它是否与真实/公共服务器使用的匹配?请参见从命令行获取SSL服务器的证书指纹 - Charles Duffy
错误非常简单:No such file or directory: '/Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl'。你在那个位置有这个文件吗? - Lie Ryan
@LieRyan,...是的,第二个错误很简单(下载的文件名没有正确传递给pip),但第一个错误非常令人担忧。如果OP使用的下载工具没有检查SSL证书类型,并且他们的系统配置为接受由任何人MITM的CA证书所有权,则他们尝试通过第二组说明安装的内容可能会被木马程序感染。 - Charles Duffy
如果这是一个安全服务或者是一个“授权”的攻击者,那么可能就不是我们能够处理的事情了。 - Charles Duffy
显示剩余3条评论
2个回答

1

解决:

1.前往https://pypi.org/project/sh/#files下载sh-1...14.tar.gz

2.执行命令:sudo easy_install /YourPath/sh-1.12.14.tar.gz

yihuyang:~ zhangkuixun$ python 
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sh
>>> 

感谢 @Charles Duffy 的帮助。

-1

以下是我在RHEL 6.8上的解决方法:

[root@ggsource bin]# easy_install sh
Searching for sh
Reading https://pypi.python.org/simple/sh/
Best match: sh 1.12.14
Downloading https://files.pythonhosted.org/packages/7c/71/199d27d3e7e78bf448bcecae0105a1d5b29173ffd2bbadaa95a74c156770/sh-1.12.14.tar.gz#sha256=b52bf5833ed01c7b5c5fb73a7f71b3d98d48e9b9b8764236237bdc7ecae850fc
Processing sh-1.12.14.tar.gz
Running sh-1.12.14/setup.py -q bdist_egg --dist-dir /tmp/easy_install-d_0PyJ/sh-1.12.14/egg-dist-tmp-wx4sqa
warning: no previously-included files matching '*.pyc' found anywhere in distribution
zip_safe flag not set; analyzing archive contents...
sh: module references __file__
sh: module references __path__
sh: module MAY be using inspect.stack
Adding sh 1.12.14 to easy-install.pth file

Installed /usr/lib/python2.6/site-packages/sh-1.12.14-py2.6.egg
Processing dependencies for sh
Finished processing dependencies for sh
[root@ggsource bin]# python
Python 2.6.6 (r266:84292, Jul 23 2015, 05:13:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sh
>>> print(sh.hostname())
ggsource.localdomain

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接