Google Compute Engine error installing python pysftp/cryptography package - python-2.7

I was trying to install pysftp in my Google Compute Engine VM, but getting the error bellow:
$ sudo pip install pysftp
......
c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory
or
c/_cffi_backend.c:2:20: fatal error: ffi.h: No such file or directory

I've found out it is a common problem associated with the cryptography module, and the lack of native installation of dev base packages. So, the problem was solved by installing the following dependencies at first:
Debian/Ubuntu:
$ sudo apt-get install build-essential libssl-dev libffi-dev python-dev
Fedora:
$ sudo yum install gcc libffi-devel python-devel openssl-devel

Related

How to install python-mysqldb for Python 2.7 in Ubuntu 20.04 (Focal Fossa)?

I've tried "apt-get install python-mysqldb" which results in:
root#ps1svr:~# apt-get install python-mysqldb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python-mysqldb is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'python-mysqldb' has no installation candidate
Note: "apt-get install python3-mysqldb" works, however I have a lot of code written for Python 2.x which no longer runs, and this is causing enough problems that I'm probably going to have to reinstall Ubuntu 18.04
Also you can just add the Ubuntu 18.04 repositoery to install the python-mysqldb package:
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu bionic main'
sudo apt update
sudo apt install -y python-mysqldb
This will download, build and install it for all users, using pip
sudo apt install libmysqlclient-dev python2.7-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py
sudo wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h -O /usr/include/mysql/my_config.h
sudo pip2 install MySQL-python
Answer found from MySQLdb install error - _mysql.c:44:23: error: my_config.h: No such file or directory

Sentry compile fails with " error: command 'gcc' failed with exit status 1"

Been trying to install Sentry on CentOS 6.5. I have installed the prerequisites i.e Python 2.7.9
[root#localhost poduori]# python -V
Python 2.7.9
I used pyenv to change from the pre-installed python version 2.6.6 (pyenv install 2.7.9). When I try to install sentry I get the below output and error;
NB: I had already run it once hence it using cached.
pip2.7 install sentry
The full error output can be found here https://www.dropbox.com/s/64w6b7dswgzs9cb/Sentry_error.txt?dl=0
or
Sentry error txt file
A summary of the error I'm getting is below
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/root/.pyenv/versions/2.7.9/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-PSGsNT/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-UYMAyw-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-PSGsNT/cffi
The output was too long to post here so I used dropbox instead.
libffi is already installed.
root#localhost user]# rpm -qa|grep libffi
libffi-3.0.5-3.2.el6.x86_64
I already installed all the development tools,
yum groupinstall "Development tools" (including gcc compiler) but I still get the same error. Kindly assist.
ERROR: /bin/sh: xslt-config: command not found
** make sure the development packages of libxml2 and libxslt are installed **
c/_cffi_backend.c:13:17: error: ffi.h: No such file or directory
You need to install dev packages first one (it let you out of this w/ pre-built libs) is libxslt-dev, second one is python-dev. Exact names depends on your distro.
Using ubuntu i solved this by:
Installing setuptools with :
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
created a file requisits.sh
inserted the content:
#! /bin/bash
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install python-dev
sudo apt-get install setuptools
sudo apt-get install python-pip
sudo apt-get install libxslt1-dev
sudo apt-get install libxslt-dev
sudo apt-get install libxml2-dev
sudo apt-get install libz-dev
sudo apt-get install libffi-dev
sudo apt-get install libssl-dev
put execution chmod +x requisits.sh
executed:
./requisits.sh
entered the password and answered y/n when prompted.
and finally :
if using virtualenv:
pip install -U sentry
else
sudo pip install -U sentry

"error: command 'x86_64-linux-gnu-gcc' failed with exit status 1" in virtualenv

Environment: Linux Mint 17 Cinnamon.
This error is displayed:
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
when attempting the following in a virtualenv:
pip install lxml
pip install pillow
pip install pycrypto
pip install pymongo (fails but still shows in pip freeze)
There are several solutions here that recommend installing python2.7-dev:
Installing Pillow error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Installing lxml in virtualenv via pip install error: command 'x86_64-linux-gnu-gcc' failed
Pillow installation error: command 'gcc' failed with exit status 1
fatal error: Python.h: No such file or directory
I am confused by this recommendation however because it is my understanding that using something like:
sudo apt-get install python2.7-dev
would add this to the main *system* instance of Python, rather that the one in virtualenv. (see - https://unix.stackexchange.com/a/56392/92486)
Can I add python2.7-dev just to the virtualenv version of Python?
Most of the time these are dependency-issues.
Following the stack-trace of the gcc compiler one can see the missing files. Sometimes installing the Python development packages is not enough.
For example:
I tried to do pip install requests[security] in my virtualenv foo. This is the result that the pip-installer gave me.
Failed building wheel for cryptography
Running setup.py bdist_wheel for cffi
Stored in directory: /root/.cache/pip/wheels/99/e7/9a/68b1c8ca6f6f92b5feebd4d9434f50712b84f6a66d1285ea21
Successfully built cffi
Failed to build cryptography
Installing collected packages: cffi, cryptography, pyOpenSSL, ndg-httpsclient, requests
Running setup.py install for cryptography
Complete output from command /opt/foo/django-cms-virtualenv/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-eZaLAG/cryptography/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-BwgYTp-record/install-record.txt --single-version-externally-managed --compile --install-headers /opt/foo/django-cms-virtualenv/include/site/python2.7/cryptography:
running install
running build
running build_py
running egg_info
writing requirements to src/cryptography.egg-info/requires.txt
writing src/cryptography.egg-info/PKG-INFO
writing top-level names to src/cryptography.egg-info/top_level.txt
writing dependency_links to src/cryptography.egg-info/dependency_links.txt
writing entry points to src/cryptography.egg-info/entry_points.txt
warning: manifest_maker: standard file '-c' not found
reading manifest file 'src/cryptography.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'docs/_build'
warning: no previously-included files matching '*' found under directory 'vectors'
writing manifest file 'src/cryptography.egg-info/SOURCES.txt'
running build_ext
building '_Cryptography_cffi_a269d620xd5c405b7' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.c -o build/temp.linux-x86_64-2.7/src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.o
src/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_a269d620xd5c405b7.c:217:25: fatal error: openssl/aes.h: Datei oder Verzeichnis nicht gefunden
#include <openssl/aes.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
The important part is the: #include <openssl/aes.h>
The compiler makes pretty clear that it is demanding this file - but it is not there in the filesystem.
Knowing that, the only thing left to do is: install the needed libraries!
Find out which package is needed for your distribution:
e.g. for Ubuntu you can go to The Ubuntu Package Search Site and enter the missing file you are looking for. In this case "aes.h"
Install the needed packages using your distributions package management tool:
e.g. for Ubuntu:
aptitude install libssl-dev
Retry with pip in your virtualenv:
pip install requests[security]
I installed python2.7-dev via Synaptic Package Manager in Linux Mint 17.
I could then accomplish the following in virtualenv:
pip install pillow
pip install pycrypto
And then I installed libxml2-dev and libxslt1-dev via Synaptic and could accomplish the following:
pip install lxml
I also did this so that the pymongo install didn't have any errors:
pip uninstall pymongo
pip install pymongo # i defined the version i needed ie pip install pymongo==2.6.2
I'm still confused how this fixes the problem, because I thought virtualenv was an isolated environment. Any clarification about this appreciated.
Work for me :
Just install python2.7-dev first
sudo apt-get install python2.7-dev
In Ubuntu 16.04.1 this worked for me:
sudo apt-get install libxml2-dev libxslt1-dev python-dev
For me the installation of lxml was failing on compilation. I followed the instructions for installation of lxml and reduced the compiler optimizations:
sudo CFLAGS="-O0" pip install lxml
After doing this, the compile of lxml succeeded.
This can be a problem in the pip. To solve, try:
sudo apt-get remove python-pip
To install pip, securely download get-pip.py.
https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
The cffi library needs libffi-dev:
sudo apt-get install libffi libffi-dev
Easiest way is:
sudo apt-get build-dep python-imaging
and then
pip install pillow
This works for me, 12.04, python2.7.6 for package lxml
sudo pip install libxml2 libxml2-dev libxslt1-dev
sudo pip install lxml

Error while installing libapache2-mod-wsgi on linux

easy_install libapache2-mod-wsgi
No local packages or download links found for libapache2modwsgi
error: Could not find suitable distribution for Requirement.parse('libapache2mod wsgi')
libapache2-mod-wsgi is not a python package. You should install it via your distribution package manager. For example, if you are in a debian based distribution:
sudo apt-get install libapache2-mod-wsgi
Or if you are working with Python 3
sudo apt-get install libapache2-mod-wsgi-py3

django_auth_ldap no module named ldap

I am trying to get the django_auth_module working but I don't think I managed to install it properly.
I downloaded the package and ran setup.py install.
Then in my settings.py file I tried to import the module ldap and it gave me the following error :
ImportError: no module named ldap
I am working on a CentOS 6 server.
Maybe it has to do with where I should install the module? The folder is in the directory just above my site folder, but maybe that's wrong...
RESOLVED :
Ok, I just needed to install the module python-ldap... problem solved!
Install missing module
Hint: To install python-ldap with pip on Ubuntu, some libraries are needed.
Use the apt-get commands to install them.
Python 2
sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
sudo pip install python-ldap
Python 3
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap
Try the below command to install for Python3.
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap