6

I am trying to import fabric.api and having issues. I installed fabric using pip and it works fin when I run import fabric in the interpreter.

But when I do from fabric.api import * it spews out an error saying "No module named api". I am using Python 2.7. What am I missing here?

Python 2.7.10 (default, Oct  6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'version' is not defined
>>> import fabric
>>> import fabric.api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named api
>>> from "fabric.api" import *
  File "<stdin>", line 1
    from "fabric.api" import *
                    ^
Stephen Kitt
  • 434,908

3 Answers3

13

Fabric has made some major API changes from v1 to v2; to see the changes, visit Upgrading from Fabric 1.x: API organization. In particular, fabric.api is removed and everything is imported directly from the top-level package. This means that your scripts won't work with the current Fabric==2.0.1 version; you have two possibilities: rewrite your code to be compliant with v2, or install the latest v1 version:

$ pip install "fabric<2"
hoefling
  • 896
0

fabric.api is part of version

1.14

you installed

2.4

please check versions

0

For those still struggling with the changes or have a long chain of tools based on fabric<2 but want to migrate to python 3 you can use

pip install fabric3

to get a working version that is python 3 compatible and uses fabric<2.

AdminBee
  • 22,803