5

I installed sh for native python, and I started using commands to install:

$ 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

When the above fails, I download sh-1.12.14-py2.py3-none-any.whl to install locally:

$ 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'

This path is right. It does exist:

$ cd /Users/zhangkuixun/Downloads/
$ ls
...
sh-1.12.14-py2.py3-none-any.whl

How can I install SH and reference it? Now the reference fails:

$ 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
>>> 
najeem
  • 1,841
  • 13
  • 29
Kuixun Zhang
  • 61
  • 1
  • 1
  • 5
  • 1
    Is `pypi.python.org` *really* using TLSV1? I almost wonder if you're subject to a man-in-the-middle attack... – Charles Duffy Dec 19 '18 at 02:18
  • ...indeed, when I look at it myself (`openssl s_client -connect pypi.python.org:443`), they're using TLSv1.2. Could you provide the fingerprint of the SSL certificate you get for that site here, so we can check whether it matches what the real/public server is using? See [Get certificate fingerprint of SSL server from command line](https://stackoverflow.com/questions/5164804/get-certificate-fingerprint-of-https-server-from-command-line) – Charles Duffy Dec 19 '18 at 02:19
  • The error is quite simple: `No such file or directory: '/Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl'` Do you have the file in that location? – Lie Ryan Dec 19 '18 at 02:25
  • @LieRyan, ...yes, the *second* error is simple (downloaded filename just not passed to `pip` correctly), but the *first* error is extremely worrisome. If the OP did the download with a tool that isn't checking SSL certificate types, and their system is configured to accept a CA cert owned by whomever's MITM'ing them, then what they're trying to install via the second set of instructions could well be trojaned. – Charles Duffy Dec 19 '18 at 02:26
  • ...granted, if that's a security service or otherwise an "authorized" attacker, it may be less of something one can do anything about. – Charles Duffy Dec 19 '18 at 02:28
  • BTW, it's better practice to edit [an unanswered question](https://stackoverflow.com/questions/53774801/download-error-on-https-pypi-python-org-simple-sh-ssl-tlsv1-alert-protocol) than to ask it over again. – Charles Duffy Dec 19 '18 at 02:32
  • @Lie Ryan @Charles Duffy Yes, I have this file. I download `sh-1.12.14-py2.py3-none-any.whl` to `/Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl`. I can execute `open /Users/zhangkuixun/Downloads/sh-1.12.14-py2.py3-none-any.whl`,Just no app can open it. – Kuixun Zhang Dec 19 '18 at 02:57
  • https://stackoverflow.com/search?q=%5Bpip%5D+TLSV1_ALERT_PROTOCOL_VERSION – phd Dec 19 '18 at 11:46

2 Answers2

1

Solved:

1.to here https://pypi.org/project/sh/#files download sh-1...14.tar.gz

2.executive command: 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
>>> 

Tanks @Charles Duffy

Kuixun Zhang
  • 61
  • 1
  • 1
  • 5
-1

This worked for me on RHEL 6.8 as below:

[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