根據paramiko官網的指示,可使用pip安裝paramiko模塊默認安裝最新的穩定版本的paramiko
使用pip安裝paramikopython
sudo pip3 install paramiko
出現一堆錯誤信息:linux
liuxin@sunshine-virtual-machine:~/work/python/python/socket/socketserver/ftp_client$ sudo pip3 install paramiko [sudo] password for liuxin: 對不起,請重試。 [sudo] password for liuxin: 對不起,請重試。 [sudo] password for liuxin: Downloading/unpacking paramiko Downloading paramiko-2.4.0-py2.py3-none-any.whl (192kB): 192kB downloaded Downloading/unpacking bcrypt>=3.1.3 (from paramiko) Downloading bcrypt-3.1.4.tar.gz (42kB): 42kB downloaded Running setup.py (path:/tmp/pip_build_root/bcrypt/setup.py) egg_info for package bcrypt warning: no previously-included files found matching 'requirements.txt' warning: no previously-included files found matching 'tasks.py' warning: no previously-included files found matching '.travis.yml' warning: no previously-included files found matching 'wheel-scripts' warning: no previously-included files found matching 'Jenkinsfile' warning: no previously-included files found matching '.jenkins' warning: no previously-included files matching '*' found under directory '.jenkins' warning: no previously-included files matching '*' found under directory 'wheel-scripts' no previously-included directories found matching '.travis' Downloading/unpacking pynacl>=1.0.1 (from paramiko) Downloading PyNaCl-1.2.1.tar.gz (3.3MB): 3.3MB downloaded Running setup.py (path:/tmp/pip_build_root/pynacl/setup.py) egg_info for package pynacl Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found c/_cffi_backend.c:15:17: fatal error: ffi.h: 沒有那個文件或目錄 #include <ffi.h> ^ compilation terminated. Traceback (most recent call last): File "/usr/lib/python3.4/distutils/unixccompiler.py", line 116, in _compile extra_postargs) File "/usr/lib/python3.4/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/usr/lib/python3.4/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/usr/lib/python3.4/distutils/spawn.py", line 162, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'i686-linux-gnu-gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.4/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py", line 185, in run cmd = self.call_command('install_lib', warn_dir=0) File "/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py", line 171, in call_command self.run_command(cmdname) File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib/python3/dist-packages/setuptools/command/install_lib.py", line 21, in run self.build() File "/usr/lib/python3.4/distutils/command/install_lib.py", line 109, in build self.run_command('build_ext') File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 49, in run _build_ext.run(self) File "/usr/lib/python3.4/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/usr/lib/python3.4/distutils/command/build_ext.py", line 448, in build_extensions self.build_extension(ext) File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 178, in build_extension _build_ext.build_extension(self,ext) File "/usr/lib/python3.4/distutils/command/build_ext.py", line 503, in build_extension depends=ext.depends) File "/usr/lib/python3.4/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/usr/lib/python3.4/distutils/unixccompiler.py", line 118, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'i686-linux-gnu-gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1025, in run_setup run_setup(setup_script, args) File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 50, in run_setup lambda: execfile( File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 100, in run return func() File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 52, in <lambda> {'__file__':setup_script, '__name__':'__main__'} File "/usr/lib/python3/dist-packages/setuptools/compat.py", line 78, in execfile exec(compile(source, fn, 'exec'), globs, locs) File "setup.py", line 236, in <module> cmdclass={ File "/usr/lib/python3.4/distutils/core.py", line 163, in setup raise SystemExit("error: " + str(msg)) SystemExit: error: command 'i686-linux-gnu-gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 17, in <module> File "/tmp/pip_build_root/pynacl/setup.py", line 251, in <module> "Programming Language :: Python :: 3.6", File "/usr/lib/python3.4/distutils/core.py", line 108, in setup _setup_distribution = dist = klass(attrs) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 239, in __init__ self.fetch_build_eggs(attrs.pop('setup_requires')) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 264, in fetch_build_eggs replace_conflicting=True File "/usr/lib/python3/dist-packages/pkg_resources.py", line 620, in resolve dist = best[req.key] = env.best_match(req, ws, installer) File "/usr/lib/python3/dist-packages/pkg_resources.py", line 858, in best_match return self.obtain(req, installer) # try and download/install File "/usr/lib/python3/dist-packages/pkg_resources.py", line 870, in obtain return installer(requirement) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 314, in fetch_build_egg return cmd.easy_install(req) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 616, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 646, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 834, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1040, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1028, in run_setup raise DistutilsError("Setup script exited with %s" % (v.args[0],)) distutils.errors.DistutilsError: Setup script exited with error: command 'i686-linux-gnu-gcc' failed with exit status 1 Complete output from command python setup.py egg_info: Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found Package libffi was not found in the pkg-config search path. Perhaps you should add the directory containing `libffi.pc' to the PKG_CONFIG_PATH environment variable No package 'libffi' found c/_cffi_backend.c:15:17: fatal error: ffi.h: 沒有那個文件或目錄 #include <ffi.h> ^ compilation terminated. Traceback (most recent call last): File "/usr/lib/python3.4/distutils/unixccompiler.py", line 116, in _compile extra_postargs) File "/usr/lib/python3.4/distutils/ccompiler.py", line 909, in spawn spawn(cmd, dry_run=self.dry_run) File "/usr/lib/python3.4/distutils/spawn.py", line 36, in spawn _spawn_posix(cmd, search_path, dry_run=dry_run) File "/usr/lib/python3.4/distutils/spawn.py", line 162, in _spawn_posix % (cmd, exit_status)) distutils.errors.DistutilsExecError: command 'i686-linux-gnu-gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.4/distutils/core.py", line 148, in setup dist.run_commands() File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands self.run_command(cmd) File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py", line 185, in run cmd = self.call_command('install_lib', warn_dir=0) File "/usr/lib/python3/dist-packages/setuptools/command/bdist_egg.py", line 171, in call_command self.run_command(cmdname) File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib/python3/dist-packages/setuptools/command/install_lib.py", line 21, in run self.build() File "/usr/lib/python3.4/distutils/command/install_lib.py", line 109, in build self.run_command('build_ext') File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command self.distribution.run_command(command) File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command cmd_obj.run() File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 49, in run _build_ext.run(self) File "/usr/lib/python3.4/distutils/command/build_ext.py", line 339, in run self.build_extensions() File "/usr/lib/python3.4/distutils/command/build_ext.py", line 448, in build_extensions self.build_extension(ext) File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 178, in build_extension _build_ext.build_extension(self,ext) File "/usr/lib/python3.4/distutils/command/build_ext.py", line 503, in build_extension depends=ext.depends) File "/usr/lib/python3.4/distutils/ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/usr/lib/python3.4/distutils/unixccompiler.py", line 118, in _compile raise CompileError(msg) distutils.errors.CompileError: command 'i686-linux-gnu-gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1025, in run_setup run_setup(setup_script, args) File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 50, in run_setup lambda: execfile( File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 100, in run return func() File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 52, in <lambda> {'__file__':setup_script, '__name__':'__main__'} File "/usr/lib/python3/dist-packages/setuptools/compat.py", line 78, in execfile exec(compile(source, fn, 'exec'), globs, locs) File "setup.py", line 236, in <module> cmdclass={ File "/usr/lib/python3.4/distutils/core.py", line 163, in setup raise SystemExit("error: " + str(msg)) SystemExit: error: command 'i686-linux-gnu-gcc' failed with exit status 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 17, in <module> File "/tmp/pip_build_root/pynacl/setup.py", line 251, in <module> "Programming Language :: Python :: 3.6", File "/usr/lib/python3.4/distutils/core.py", line 108, in setup _setup_distribution = dist = klass(attrs) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 239, in __init__ self.fetch_build_eggs(attrs.pop('setup_requires')) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 264, in fetch_build_eggs replace_conflicting=True File "/usr/lib/python3/dist-packages/pkg_resources.py", line 620, in resolve dist = best[req.key] = env.best_match(req, ws, installer) File "/usr/lib/python3/dist-packages/pkg_resources.py", line 858, in best_match return self.obtain(req, installer) # try and download/install File "/usr/lib/python3/dist-packages/pkg_resources.py", line 870, in obtain return installer(requirement) File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 314, in fetch_build_egg return cmd.easy_install(req) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 616, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 646, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 834, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1040, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1028, in run_setup raise DistutilsError("Setup script exited with %s" % (v.args[0],)) distutils.errors.DistutilsError: Setup script exited with error: command 'i686-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Cleaning up... Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/pynacl Storing debug log for failure in /home/liuxin/.pip/pip.log
查看錯誤日誌時發現一條信息:git
No package 'libffi' found
因此使用下面安裝libffi:github
sudo apt-get install libffi-dev
再次使用pip3安裝paramiko模塊又提示以下錯誤:socket
error in cryptography setup command: Invalid environment marker: python_version < '3'
別灰心,出現別的錯誤說明有進展
上網搜了一下這個錯誤找到一個解決方案:https://github.com/ansible/ansible/issues/31741
看到沒?它也在安裝libffi,至少說明咱們的方向沒有錯, 按照大神的提示執行一下指令:post
sudo pip3 install --upgrade setuptools sudo apt-get install libffi-dev libssl-dev
再次安裝paramiko測試
sudo pip3 install paramiko
安裝成功,打開python3解釋器測試模塊:fetch
Successfully installed paramiko pyasn1 bcrypt cryptography pynacl cffi idna asn1crypto pycparser Cleaning up... liuxin@sunshine-virtual-machine:~/work/python/python/socket/socketserver/ftp_client$ python3 Python 3.4.3 (default, Nov 28 2017, 16:40:41) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import paramiko >>>
ok, 搞定ui
總結:
在使用pip3安裝paramiko模塊執行如下指令:spa
sudo pip3 install --upgrade setuptools sudo apt-get install libffi-dev libssl-dev sudo pip3 install paramiko