Python - No module named 'fabric.api - Windows 10
Asked Answered
P

2

7

I just installed Python 3.7 and Fabric.

It works perfectly on my laptop, but not on my desktop.

The error :

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files (x86)\Python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\python_project\myProject\env\Scripts\fab.exe\__main__.py", line 9, in <module>
File "c:\python_project\myProject\env\lib\site-packages\invoke\program.py", line 352, in run
self.parse_collection()
File "c:\python_project\myProject\env\lib\site-packages\invoke\program.py", line 444, in parse_collection
self.load_collection()
File "c:\python_project\myProject\env\lib\site-packages\fabric\main.py", line 82, in load_collection
super(Fab, self).load_collection()
File "c:\python_project\myProject\env\lib\site-packages\invoke\program.py", line 661, in load_collection
module, parent = loader.load(coll_name)
File "c:\python_project\myProject\env\lib\site-packages\invoke\loader.py", line 76, in load
module = imp.load_module(name, fd, path, desc)
File "C:\Program Files (x86)\Python37-32\lib\imp.py", line 235, in load_module
return load_source(name, filename, file)
File "C:\Program Files (x86)\Python37-32\lib\imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\python_project\myProject\fabfile.py", line 2, in <module>
from fabric.api import task, run, env, settings, hide
ModuleNotFoundError: No module named 'fabric.api'

But Fabric seem to be installed ?

C:\Users\MyUser>pip install fabric
Requirement already satisfied: fabric in c:\program files (x86)\python37 32\lib\site-packages (2.4.0)

C:\Users\MyUser>pip show fabric
Name: fabric
Version: 2.4.0
Summary: High level SSH command execution
Home-page: http://fabfile.org
Author: Jeff Forcier
Author-email: [email protected]
License: BSD
Location: c:\program files (x86)\python37-32\lib\site-packages
Requires: paramiko, cryptography, invoke
Required-by:

However "fabric" didn't appear in the list when I do the following in idle (just Fabfile) :

>>> import pkgutil
>>> [name for _, name, _ in pkgutil.iter_modules()]
['fabfile', '_asyncio', '_bz2', ... 'enum', 'filecmp', 'fileinput', ...]

I also tried to uninstall/reinstall fabric, but it's still failing.

Do you have any idea why I cannot import fabric.api ?

Update :

I also created a virtual environment :

py -3 -m venv env 
code . 

Selected Python interpreter "venv" in Visual Studio code then :

python -m pip install fabric 

But i'm still facing the same error :-/

Paleolithic answered 16/10, 2018 at 19:14 Comment(0)
P
12

Well after few research I finally found a workaround by using fabric3 (a fork of Fabric, compatible python 3).

pip uninstall fabric
pip install fabric3

Link : https://pypi.org/project/Fabric3/

Paleolithic answered 16/10, 2018 at 23:39 Comment(0)
H
3

I see you have already installed fabric 2.4.0 which is great! Since you are using the fabric 2.4.0 you can't use from fabric.api import taks. fabric.api could be used if you use fabric1xx

If you want to import connection and task from fabric2.4.0 you have to do it like this

from fabric import Connection as connection, task

@task
def deploy(ctx):
    with connection(host=host, user=user) as c:
         c.run('ls -la')

Note: fabric 3 is not an official fork. I advise you to use fabric2.4.0

Hernia answered 17/10, 2018 at 7:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.