Trouble installing m2crypto with pip on OS X / macOS - macos

pip install m2crypto
Generates the following output:
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I/usr/include -I/usr/include/openssl -includeall -modern -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_m2crypto.i:30: Error: Unable to find 'openssl/opensslv.h'
SWIG/_m2crypto.i:33: Error: Unable to find 'openssl/safestack.h'
SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
error: command 'swig' failed with exit status 1
I've run:
brew install swig

I wanted a nicer way without installing manually and using only Homebrew (which also does not link openssl by default). Also using pip was a requirement. This seems to work with newest m2crypto 0.22.5. I also tested it once with m2crypto 0.22.3 and seems also to work. The OpenSSL version here is 1.0.2d:
brew install openssl
brew install swig
Finally install m2crypto on macOS in your Bash. It is a long command but it changes SWIG and clang environment variables only during pip install so that m2crypto will get all OpenSSL requirements:
env LDFLAGS="-L$(brew --prefix openssl)/lib" \
CFLAGS="-I$(brew --prefix openssl)/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I$(brew --prefix openssl)/include" \
pip install m2crypto
btw. the last command also works if you use e.g. a requirements.txt.
Update:
Additional also the command for fish shell users...
env LDFLAGS="-L"(brew --prefix openssl)"/lib" \
CFLAGS="-I"(brew --prefix openssl)"/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I"(brew --prefix openssl)"/include" \
pip install m2crypto

thanks to therealmarv env flags i was able to get this to work with the macports version of openssl/swig, this is what i did:
sudo port install openssl
sudo port install swig
sudo port install swig-python
then use therealmarv lines but replace "$(brew --prefix openssl)" with the dir from macports which should be "/opt/local"
sudo env LDFLAGS="-L/opt/local/lib" \
CFLAGS="-I/opt/local/include" \
SWIG_FEATURES="-cpperraswarn -includeall -I/opt/local/include" \
pip install M2Crypto

I just went through a lot of pain getting this working in El Capitan. Here is what I had to do:
Install OpenSSL (you have to use an older version, m2crypto will not compile otherwise)
curl -O https://www.openssl.org/source/openssl-0.9.8zg.tar.gz
tar -xvzf openssl-0.9.8zg.tar.gz
cd openssl-0.9.8zg
./Configure --prefix=/usr/local darwin64-x86_64-cc
make && make test
sudo make install
Install m2crypto
git clone https://github.com/martinpaljak/M2Crypto.git
cd M2Crypto
python setup.py build build_ext --openssl=/usr/local
sudo python setup.py install build_ext --openssl=/usr/local
AFAIK it is installed... I still have to do some testing though.

Got exact same issue on Ubuntu 18.04 LTS, while trying to execute
pip install M2Crypto==0.24.0
Did the following to get rid of it:
sudo apt-get install swig
sudo apt-get install libssl1.0-dev

This fixed my problem (Python 2.7):
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

macos v10.15.6
m2crypto v0.35.6
pip v20
Solution by therealmarv works,
If the program does not take effect, you can try to upgrade your brew packages. Before the solution.
brew update # update homebrew self
brew upgrade # upgrade all

sudo apt-get install python-m2crypto

Related

An issue with installation of ansible-pylibssh on Apple Silicon M2

I've got an issue with installation of ansible-pylibssh.
During installation
pip3 install --user ansible-pylibssh
I got
ld: library not found for -lssh
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/clang' failed with exit code 1
Could someone explain how to overcome this?
I've already done softlink
% cd /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
% sudo ln -s /opt/homebrew/Cellar/libssh/0.10.4/include/libssh/ libssh
Install libssh:
brew install libssh
Use a python virtual environment :
python3 -m venv .venv
source .venv/bin/activate
EDIT:
Install with correct compiler flags:
CFLAGS="-I $(brew --prefix)/include -I ext -L $(brew --prefix)/lib -lssh" pip install ansible-pylibssh
Thanks, #webknjaz!
OLD Additional steps not needed (preserved for history):
Install tox build tool:
pip install 'tox >= 3.19.0'
Build from source on ARM-based Macs, per the ansible-pylibssh docs:
#git clone https://github.com/ansible/pylibssh.git ~/src/github/ansible/pylibssh
# or, if you use SSH:
git clone ssh://git#github.com/ansible/pylibssh.git ~/src/github/ansible/pylibssh
cd ~/src/github/ansible/pylibssh
Use libraries installed by brew with clang:
export CFLAGS="-I $(brew --prefix)/include -I ext -L $(brew --prefix)/lib -lssh"
Build ansible-pylibssh:
tox -e build-dists
Install built ansible-pylibssh wheel:
pip install ~/src/github/ansible/pylibssh/dist/ansible_pylibssh*.whl
Additional resources that lead to this answer:
Kristof Rado's answer to Cannot install ansible-pylibssh on macOS
ansible/pylibssh GitHub issue 207 provides background on why this package is not available for macOS on ARM from PyPi (symlink/softlink to point to the libraries did not help. Correct compiler flags were the needed answer.)
If you prefer not to work with a virtual environment, this may work: replace pip commands python3 -m pip --user and python commands with python3.

I cannot install aws cli on mac os with pip - awscli: command not found

I tried to follow this tutorial.
This is what I did in the console:
pip3 install --user --upgrade awscli
after that, when I write:
pip3 --version
I'm getting:
pip 9.0.1 from /Users/user/Library/Python/3.4/lib/python/site-packages (python 3.4)
then I wrote:
pip3 install --user --upgrade awscli
this command downloaded awscli and automatically added this:
# Setting PATH for Python 3.4
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
to my .profile
Later on, just to be sure, I wrote:
source ~/.profile
and then when I type:
user$ aws
-bash: aws: command not found
I restarted the terminal with no luck also.
What's the problem here?
Here are the two steps to install AWS cli on mac OSX
FIRST
Offical version
brew install awscli
SECOND
Development version
brew install awscli --HEAD
When "pip3 install" is called with the "--user" option, it installs the aws executable in a user-specific location. This can be one of many possible locations, but the best way to find out where is with this command:
python3 -m site --user-base
On my system, this returned:
/Users/[myusername]/Library/Python/3.6
This directory has a "bin" subdirectory, and that is where the "aws" executable was located.
I figured this out from following:
pip3 install --help
https://docs.python.org/3/library/site.html#module-contents
Simple do these three steps:
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
brew install awscli should work
This is what worked for me, I experienced permission issues and had to create a local Frameworks folder first before running brew install. using macOS High Sierra
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
brew install awscli
To answer the original question about installing using pip:
sudo pip install --upgrade pip
sudo easy_install nose
sudo easy_install tornado
sudo easy_install six
sudo pip install --ignore-installed awscli
worked for me on Mojave
I had similar error, when trying to install awscli. I was following steps mentioned here by amazon [https://docs.aws.amazon.com/cli/latest/userguide/cli-install-macos.html]
I use anaconda, so when I was using pip3 install awscli --upgrade --user
it installs awscli in /Users/username/.local/lib/python3.6/
So, I used following to update awscli to anaconda-
conda install -c conda-forge awscli
I have used the following commands to install awscli :
$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ ./awscli-bundle/install -b ~/bin/aws
check version using : /Users/xxx/bin/aws --version
configure using : /Users/xxx/bin/aws configure
Was facing a similar issue. Resolved it by installing python 3.9 using brew install.
brew install python#3.9
Then reinstall awscli
I followed the below steps and it works for MacOS 10.11
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
Unzip the package.
unzip awscli-bundle.zip
And instead of given command:
'sudo /usr/local/bin/python2.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws'
which is broken due to pip, I think, I used the below command and it worked for me.
python3.6 ./awscli-bundle/install -b ~/bin/aws

pip3 installs inside virtual environment with python3.6 failing due to ssl module not available

(py36venv) vagrant#pvagrant-dev-vm:/vagrant/venvs$ pip3 install pep8
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pep8 Could not fetch URL
https://pypi.python.org/simple/pep8/: There was a problem confirming
the ssl certificate: Can't connect to HTTPS URL because the SSL module
is not available. - skipping
Could not find a version that satisfies the requirement pep8 (from
versions: ) No matching distribution found for pep8
Background information - Trying to move to python 3.6.
Installed python3.6 using the below commands:
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar -xvf Python-3.6.0.tgz
cd Python-3.6.0
./configure --enable-optimizations
make -j8 sudo
make altinstall python3.6
Created virtualenv by:
python3.6 -m venv py36venv
source py36venv/bin/activate
Tried to install pep8
(py36venv) pip3 install pep8
pip is configured with locations that require TLS/SSL, however the ssl
module in Python is not available.
Collecting pep8
Could not fetch URL https://pypi.python.org/simple/pep8/: There was a problem
confirming the ssl certificate: Can't connect to HTTPS URL because the
SSL module is not available. - skipping Could not find a version
that satisfies the requirement pep8 (from versions: ) No matching
distribution found for pep8
I followed the below steps for python3.6 installation in ubuntu 14.04 and virtualenv pip installs works fine.
Python 3.6 Installation:
sudo apt-get install python3-dev libffi-dev libssl-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar xvf Python-3.6.0.tgz
cd Python-3.6.0
./configure --enable-optimizations
make -j8
sudo make altinstall
python3.6
If seeing the following error --
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [altinstall] Error 1
try:
sudo apt-get install zlib1g-dev
Validation:
Create virtualenv in python3.6:
python3.6 -m venv testenv
source testenv/bin/activate
pip install pep8
using pip:
(testenv) vagrant#pvagrant-dev-vm:~$ pip install pep8
*Collecting pep8
Downloading pep8-1.7.0-py2.py3-none-any.whl (41kB)
100% |████████████████████████████████| 51kB 4.1MB/s
Installing collected packages: pep8
Successfully installed pep8-1.7.0*
(testenv) vagrant#pvagrant-dev-vm:~$ pip list
pep8 (1.7.0)
pip (9.0.1)
setuptools (28.8.0)
I stumbled upon the same issue when I tried to create a virtual environment utilising python3.6.0. Here is my solution for Mac OS X 10.12.2 (Py_minion comment was pretty close):
Setup
I created the environment by the following steps:
downloading python3.6.0
running
./configure --prefix=<some_path>`
make
make install
mkvirtualenv --python=<some_path/bin/python3.6> foo
So basically similar to: https://stackoverflow.com/a/11301911/1286093
An indication if you have the same issue as I had would be a similar line when running make
The necessary bits to build these optional modules were not found: _ssl
Solution
Install openssl
brew install openssl
brew unlink openssl && brew link openssl --force
Change Module/Setup or Module/Setup.dist
You can find those files in the directory of the downloaded Python version.
Comment in and, if necessary change, lines 209 - 211 (I had to change the SSL variable to my openssl location).
SSL=/usr/local/opt/openssl <---- THIS DEPENDS ON YOUR INSTALLATION
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
Given that this was the location of openssl
Set environment variables
export CFLAGS="-I$(brew --prefix openssl)/include"
export LDFLAGS="-L$(brew --prefix openssl)/lib"
make and install again
Running
./configure --prefix=<some_path>`
make
make install
mkvirtualenv --python=<some_path/bin/python3.6> foo
again did the trick for me
Running make reported to me in the shell output:
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_sqlite3 _ssl _tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
What solved the problem in my case (Linux Mint 18.1, openssl already installed) was editing the setup.py in the Python-3.6.0 folder adding there the path to where the openssl installation put the ssl.h file on my system into ( /usr/include/openssl/ssl.h ). Here the section in which I have added the line '/usr/include':
# Detect SSL support for the socket module (via _ssl)
search_for_ssl_incs_in = [
'/usr/local/ssl/include/',
'/usr/contrib/ssl/include/',
'/usr/include/'
]
ssl_incs = find_file('openssl/ssl.h', inc_dirs,
search_for_ssl_incs_in
)
I have solved this problem on Ubuntu-16.04.1.
First you need to install necessary libraries. To install open Terminal (Ctrl+Alt+T), then type;
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
After that go the directory where your python file is then reconfigure and reinstall python3.6 .
cd /opt/Python3.6/
./configure
make
sudo make install
NOTE
If you installed Python3.6 via ppa, then reinstall it again;
sudo apt-get install python3.6
Now you should be able to use pip3.6
I ran into the same error when building Python 3.6.1 from source under CentOS 7.
For CentOS7, I had to first:
sudo yum install openssl-dev
Then:
./configure --enable-optimizations
make altinstall
Now pip3.6 works :-)
A complete script can be found HERE
Install Prerequisites
For RHEL/CentOS
sudo yum -y install gcc gcc-c++ zlib zlib-devel libffi-devel openssl-devel wget
For Ubuntu/Debian
sudo apt-get -y install build-essential python-dev python-setuptools python-pip
python-smbus libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev
tk-dev libssl-dev openssl libffi-dev wget
Download Python
Modify for the version of python you want
Python Versions
cd /var/tmp
sudo wget https://www.python.org/ftp/python/3.x.x/Python-x.x.x.tgz
sudo tar xf Python-3.*.tgz
cd Python-3*
Configure/Make/Install
sudo ./configure --enable-optimizations --enable-shared --prefix=/usr/local
sudo make && make altinstall
Cleanup Shared Library & Add to Path
Stripping the shared library of debugging symbols can speed up execution when running parallel scripts.
sudo make && make altinstall
sudo strip /usr/local/lib/libpython3.7m.so.1.0
sudo echo 'export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib' >> /etc/profile.d/python.sh
sudo echo 'export PATH=${PATH}:~/usr/local/bin/' >> /etc/profile.d/python.sh
sudo echo '/usr/local/lib' >> /etc/ld.so.conf
sudo ldconfig
Reference
Gist
Stack Overflow
Stack Overflow
Daniel Erikson
Unix StackExchange
TLDP

Error installing mysql-python: library not found for -lssl

I'm having trouble installing mysql-python. Created a new virtualenv and when installing mysql-python... here's the error message:
(env)$ pip install mysql-python
Collecting mysql-python
...
clang -bundle -undefined dynamic_lookup -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk build/temp.macosx-10.12-x86_64-2.7/_mysql.o -L/usr /local/Cellar/mysql/5.7.16/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.12-x86_64-2.7/_mysql.so
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1
Using homebrew, I have installed:
libressl
openssl
openssl#1.1
mysql
Already tried to brew link but brew refuses to do so.
The OS is MacOS Sierra.
Can anyone help? Thanks!
You can set ssl library path explicitly.
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
I tried updating Xcode's CLT, uninstalling mysql, checking mysql_config, etc., but had no luck.
I found that running brew info openssl shows:
...
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
...
Running those two commands, followed by pip install, worked for me (in my case when installing mysqlclient).
Solved it with these steps:
brew uninstall mysql
brew install mysql-connector-c
pip install mysql-python
brew unlink mysql-connector-c
brew install mysql
Found the answer here https://stackoverflow.com/a/25920020/576192
Not sure if this is the right way, but this is how I managed to solve it.
I'm able to fix the error by running:
pip install -r requirements.txt --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib"
I was finally able to fix it by
xcode-select --install
I was sure I had already done that... but obviously I hadn't. Definitely worth a shot!
For me on mac, running this command solved the issue
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
Actually we need to set ssl library path to get this issue fixed.
Worked for me by doing this
$ brew uninstall mysql
$ brew install mysql-connector-c
$ brew unlink mysql-connector-c
$ brew install mysql
$ pip install mysql-python
Which is a slightly altered version of the recipe above (note: pip install at the end!)
If you want to install mysql-python, I suggest you to install mysqlclient instead. The authors of these two modules are the same. By far, the authors all turn to keep maintaining mysqlclient. mysqlclient supports both Python 2 and Python 3. And you can use the same codes like mysql-python. Blew is my installation solution for you.
$ brew info openssl
$ brew unlink mysql-connector-c
$ brew install mysql
$ brew link --overwrite mysql-connector-c
$ pip install mysqlclient
If there is an error before pip install mysqlclient. Please fix it according to methane's answer.
And run pip install mysqlclient again.
Or download and install .dmg from the MySQL dev site: https://dev.mysql.com/downloads/file/?id=467834
For those of you who are installing MySQL v5.7 with Brew
Uninstall mysql-connector-c
$ brew uninstall mysql-connector-c
Install specific version, very likely you need to uninstall other installed versions
$ brew install mysql#5.7
You will need to add it to the PATH, since this is 'keg-only' formulae, this is printed after it is installed
$ echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
Replace ~/.zshrc with the appropriate file.
Install mysql-connector-c
$ brew install mysql-connector-c
Check it is installed properly
$ which mysql
# /usr/local/opt/mysql#5.7/bin/mysql
$ mysql_config
# Usage: /usr/local/opt/mysql#5.7/bin/mysql_config [OPTIONS]
Compiler: Clang 10.0.0.10001145
Options:
--cflags [-I/usr/local/opt/mysql#5.7/include/mysql ]
--cxxflags [-I/usr/local/opt/mysql#5.7/include/mysql ]
--include [-I/usr/local/opt/mysql#5.7/include/mysql]
--libs [-L/usr/local/opt/mysql#5.7/lib -lmysqlclient -lssl -lcrypto]
--libs_r [-L/usr/local/opt/mysql#5.7/lib -lmysqlclient -lssl -lcrypto]
--plugindir [/usr/local/opt/mysql#5.7/lib/plugin]
--socket [/tmp/mysql.sock]
--port [0]
--version [5.7.24]
--libmysqld-libs [-L/usr/local/opt/mysql#5.7/lib -lmysqld -lssl -lcrypto]
--variable=VAR VAR is one of:
pkgincludedir [/usr/local/opt/mysql#5.7/include/mysql]
pkglibdir [/usr/local/opt/mysql#5.7/lib]
plugindir [/usr/local/opt/mysql#5.7/lib/plugin]
Now install mysqlclient
$ pip install mysqlclient

ejabberd installation issue for mac

I am installing ejabberd by using source code. I have take the clone from git : https://github.com/processone/ejabberd.git. and followed steps:
Git: brew install git
Erlang /OTP: brew install erlang
Autoconf: brew install autoconf
Automake: brew install automake
Openssl: brew install openssl
Expat: brew install expat
Libyaml: brew install libyaml
Libiconv: brew install libiconv
Sqlite: brew install sqlite
chmod +x autogen.sh
./autogen.sh
export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/local/opt/expat/lib"
export CFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include -I/usr/local/opt/expat/include"
export CPPFLAGS="-I/usr/local/opt/openssl/include/ -I/usr/local/include -I/usr/local/opt/expat/include"
./configure --prefix=$HOME/my-ejabberd --enable-mysql
make
above command is working correctly. but "sudo make install" have the problem.
Configuration files
/usr/bin/install -c -d -m 750 -g pravin //etc/ejabberd
install: pravin: Invalid argument
make: *** [install] Error 67
Please help me.
Thanks in advance.
just brew install ejabberd for current release or brew install ejabberd --HEAD to install current git master HEAD

Resources