I came across this "ImportError: cannot import name 'isMappingType' " in the middle of process to deploy fabfile for a Django Project.
1.Here is the structure of my fabfile.py
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
from fabric.contrib.files import append, exists, sed
env.hosts = ["127.0.0.1"]
env.user = raw_input('Please enter user:')
def deploy():
sudo("apt-get update -y")
sudo("apt-get install git -y")
sudo("apt-get install postgresql libpq-dev python-dev python-pip -y")
code_dir = 'backend-directory'
if exists(code_dir):
run('cd %s && git pull' % (code_dir,))
else:
run("git clone git://serveraddress/projects/backend-directory")
with cd(code_dir):
sudo("pip install virtualenv")
run("virtualenv -p /usr/bin/python3.4 venv")
run("source venv/bin/activate")
#sudo("pip install -r requirements/dev.txt")
sudo("pip install -r requirements/production.txt")
with settings(warn_only=True):
with settings(sudo_user = 'postgres'):
sudo("psql -c " + '"CREATE USER new_user WITH PASSWORD ' + "'new_password';" + '"')
sudo("psql -c 'ALTER USER new_user CREATEDB;'")
sudo("psql -c 'CREATE DATABASE newdb;'")
sudo("psql -c 'GRANT ALL PRIVILEGES ON DATABASE 'newdb' to new_user;'")
if run("nginx -v").failed:
sudo(" apt-get install nginx -y")
code_dir = 'frontend-directory'
if exists(code_dir):
run('cd %s && git pull' % (code_dir,))
else:
run("git clone git://serveraddress/frontend-directory")
code_dir = 'backend-directory/project_site'
with cd(code_dir):
run("python manage.py makemigrations --settings=project.settings.development")
run("python manage.py migrate --settings=project.settings.development")
sudo("/etc/init.d/nginx start")
with settings(warn_only=True):
if run("find /etc/uwsgi").failed:
sudo("mkdir /etc/uwsgi")
if run("find /etc/uwsgi/vassals").failed:
sudo("mkdir /etc/uwsgi/vassals")
if run("find /etc/uwsgi/vassals/pam_uwsgi.ini").failed:
sudo("ln -s ~/backend-direcoty/project_site/pam_uwsgi.ini /etc/uwsgi/vassals/")
run("uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid www-data")
Next, I have executed the below command in virtual env
(venv)praneeth@praneeth-Latitude-E6400 ~/wru-pam $ fab deploy
I got the following traceback:-
Traceback (most recent call last):
File "/home/praneeth/wru-pam/venv/bin/fab", line 9, in <module>
load_entry_point('Fabric==1.10.1', 'console_scripts', 'fab')()
File "/home/praneeth/wru-pam/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 474, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/praneeth/wru-pam/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2582, in load_entry_point
return ep.load()
File "/home/praneeth/wru-pam/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2265, in load
return self._load()
File "/home/praneeth/wru-pam/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2268, in _load
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/praneeth/wru-pam/venv/lib/python3.4/site-packages/fabric/main.py", line 12, in <module>
from operator import isMappingType
ImportError: cannot import name 'isMappingType'
What might be the reason for this import error ?
fabric
doesn't support Python 3:
Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
See also other points and workarounds at:
From what I understand, migrating to invoke
is the first thing to consider.
Quick test demonstrating the problem:
$ python2.7
>>> from operator import isMappingType
>>>
$ python3.4
>>> from operator import isMappingType
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'isMappingType'