Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - No module named 'fabric.api - Windows 10

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 :-/

like image 805
Sqdz Avatar asked Oct 16 '18 19:10

Sqdz


People also ask

Does fabric work with Python3?

Project description. Fabric3 is a fork of Fabric to provide compatability with Python 3.4+. The port still works with Python 2.7.

How do you use fabric in Python?

Fabric is a Python library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks. Typical usage involves creating a Python module containing one or more functions, then executing them via the fab command-line tool.


Video Answer


1 Answers

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/

like image 125
Sqdz Avatar answered Oct 22 '22 04:10

Sqdz