Fabric: py2.7.5 fab error: ImportError: cannot import name NetworkError

Created on 12 Jul 2018  ·  6Comments  ·  Source: fabric/fabric

File "/usr/lib/python2.7/site-packages/fabric/network.py", line 16, in
from fabric.exceptions import NetworkError
ImportError: cannot import name NetworkError
what can I do?

Most helpful comment

I'm just that slow, only adding 3 around when others start to drop 2 😂

Also, yea I don't get this error, either the package is installed incorrectly (the usual cause of import errors like this - setuptools causing a problem) or one is trying to follow version 1 docs with version 2 installed.

All 6 comments

no one can answer me?

Hi @neemxyang - there isn't really enough information to go on. It looks like you're using Fabric 1, and there's nothing that would indicate why those imports fail.

My suggestion would be uninstall and reinstall Fabric into your environment and see if that fixes the issue. If that doesn't work, try creating a fresh virtual environment and installing Fabric into that. Keep in mind that you'll need to use Fabric 1.x, as 2.x doesn't support Python 2.

Fabric-2.x does support Python 2.7, it's just that Fabric-1.x does not support Python 3

The error originally posted here, on its own, seems impossible. Maybe there's a very serious pip install or python path problem such that fabric is not really installed. We'd need much more information to be able to provide any help at all.

Fabric-2.x does support Python 2.7, it's just that Fabric-1.x does not support Python 3

Thanks - I've been working on a few packages that have dropped Python 2 support and forgot that Fabric was not the one of them.

I'm just that slow, only adding 3 around when others start to drop 2 😂

Also, yea I don't get this error, either the package is installed incorrectly (the usual cause of import errors like this - setuptools causing a problem) or one is trying to follow version 1 docs with version 2 installed.

I was getting the following error when executing a fabric script I was using Python 3.5.3

* from fabric.exceptions import NetworkError
ImportError: can not import name 'NetworkError' *

I solve it by removing fabric inside my virtualenv and installing fabric3:

pip uninstall fabric

pip install fabric3

(venv-book-tuto) root@cs-6000-devshell-vm-842dba28-6daa-4d35-9b97-4b7c0ff7b2db:/home/<user>/venv-book-tuto/django# fab configure_postgres
Traceback (most recent call last):
  File "/home/<user>/venv-book-tuto/bin/fab", line 10, in <module>
    sys.exit(program.run())
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/invoke/program.py", line 352, in run
    self.parse_collection()
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/invoke/program.py", line 444, in parse_collection
    self.load_collection()
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/fabric/main.py", line 82, in load_collection
    super(Fab, self).load_collection()
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/invoke/program.py", line 661, in load_collection
    module, parent = loader.load(coll_name)
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/invoke/loader.py", line 76, in load
    module = imp.load_module(name, fd, path, desc)
  File "/home/<user>/venv-book-tuto/lib/python3.5/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/home/<user>/venv-book-tuto/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/<user>/venv-book-tuto/django/fabfile.py", line 42, in <module>
    from fabric.api import *
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/fabric/api.py", line 10, in <module>
    from fabric.context_managers import (cd, hide, settings, show, path, prefix,
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/fabric/context_managers.py", line 27, in <module>
    from fabric.state import output, win32, connections, env
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/fabric/state.py", line 9, in <module>
    from fabric.network import HostConnectionCache, ssh
  File "/home/<user>/venv-book-tuto/lib/python3.5/site-packages/fabric/network.py", line 16, in <module>
    from fabric.exceptions import NetworkError
ImportError: cannot import name 'NetworkError'
Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuvadm picture yuvadm  ·  5Comments

SamuelMarks picture SamuelMarks  ·  3Comments

26huitailang picture 26huitailang  ·  3Comments

omzev picture omzev  ·  6Comments

bitprophet picture bitprophet  ·  6Comments