Cannot link gmp: library not found for -lgmp - gcc

I'm trying to install fastecdsa on macOS BigSur (M1 chip) by running
(venv) $ pip3 install fastecdsa
and even though I previously installed gmp:
$ brew install gmp
it cant find the lib, no matter what I do
src/curve.h:4:10: fatal error: 'gmp.h' file not found
#include "gmp.h"
Although the error changed when I created a symlink
ln -s /opt/homebrew/include/gmp.h /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
and now I get:
ld: library not found for -lgmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/gcc' failed with exit code 1
I also tried:
passing the path via env CFLAGS, LDFLAGS and both via global env export (export CFLAGS=...)
LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib pip3 install fastecdsa
CFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include pip3 install fastecdsa
xcode-select --install
endlessly brew uninstall gmp and brew install gmp, even brew reinstall gmp and brew unlink gmp
installing rosetta2
turning it off and on again
I can't put my finger on it :(

You may have resolved this by now, but just to say that I ran into something similar, and the solution for me was to tell ld to look in the homebrew library path. Run this/add it to ~/.profile:
export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/lib
export INCLUDE_PATH=$INCLUDE_PATH:/opt/homebrew/include
(I didn't need INCLUDE_PATH in my case, but it looks like you might!)
After that, perhaps your python commands will start working!

enter image description here
use the setup.py to install and modify the setup.py as the image

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.

Unable to install PyAudio on M1 Mac [PortAudio already installed]

I have visited many forums, tried diffrent methods like brew, pip, port and many more but still am facing the same error.
View this Image for more detail
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/gcc' failed with exit code 1
Can anyone help?
These steps worked on M1 Pro chips
Install portaudio
brew install portaudio
Link portaudio
brew link portaudio
Copy the path where portaudio was installed (use it in the next step)
brew --prefix portaudio
Create .pydistutils.cfg in your home directory
sudo nano $HOME/.pydistutils.cfg
then paste the following
[build_ext]
include_dirs=<PATH FROM STEP 3>/include/
library_dirs=<PATH FROM STEP 3>/lib/
Install pyaudio
pip install pyaudio
or
pip3 install pyaudio
For me it was:
brew install portaudio
python -m pip install --global-option='build_ext' --global-option='-I/opt/homebrew/Cellar/portaudio/19.7.0/include' --global-option='-L/opt/homebrew/Cellar/portaudio/19.7.0/lib' pyaudio
This Solution is tested on M1 Macs[Please do check with other].
After the installation of HomeBrew on your system, perform the installation of PortAudio. Next follow the steps mentioned below:
Use the command to install PortAudio
sudo brew install portaudio
After successful installation of PortAudio, enter the following command.
sudo nano $HOME/.pydistutils.cfg
Next, enter the following lines in the opened window
[build_ext]
include_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/include/
include_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/lib/
Note: PortAudio location may be different for you and also don't forget to replace your PC username.
Finally run the command
pip install pyaudio
or
pip3 install pyaudio
The main challenge we're encountering here is that pyaudio doesn't know where to find the portaudio libraries since, according to the source, it only looks in these locations for darwin platform installations:
include_dirs += ['/usr/local/include', '/usr/include']
external_libraries_path += ['/usr/local/lib', '/usr/lib']
This won't do if you're using a homebrew installation of portaudio, particularly so with Apple Silicon since there isn't a pre-built wheel in PyPi. This means setuptools/pip will need to build the package from source.
There are a few ways of configuring setuptools to use additional paths, including passing arguments, using a .pydistutils.cfg file, among others, but the second option worked for me given I'm installing pyaudio to a few Python environments.
Building off of some of the answers above, you can copy the following below to install pyaudio in one go.
# Install portaudio, will print list of paths where it's been installed if already done
brew list portaudio || brew install portaudio
# Link portaudio, will print a warning if already linked
brew link portaudio
# Create a pydistutils config file with the portaudio lib paths set correctly (no copying/pasting paths required)
cat <<EOF >> .pydistutils.cfg
[build_ext]
include_dirs=`brew --prefix portaudio`/include/
library_dirs=`brew --prefix portaudio`/lib/
EOF
# install (build) package with pip
python -m pip install pyaudio
All we're doing is telling setuptools to also look for C/C++ headers where portaudio has been installed by homebrew.
vkshah has an error in his second line. It should ready library_dirs instead of include_dirs:
include_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/include/
library_dirs=/Users/<enter-your-system-username>/homebrew/Cellar/portaudio/19.20140130/lib/```
For me, I am running Big Sur on an M1 Mac. I followed all the instructions mentioned in other threads to:
install portaudio
arch -arm64 brew install portaudio
start a venv
python3 -m venv env
source env/bin/activate
install pyaudio
arch -arm64 pip install --no-cache-dir --global-option='build_ext' --global-option='-I/opt/homebrew/include' --global-option='-L/opt/homebrew/lib' pyaudio==0.2.11
TIP #1
If you see error on portaudio.h file not found, the solution is specifying the pyaudio version at the end. Because it kept trying to install version '0.2.12' which failed. I specify the version of pyaudio to '0.2.11' (see above).
TIP #2
After successfully installing pyaudio, you may see error PyAudio C module _portaudio, that is due to pip built it(_portaudio.cpython-36m-darwin.so) in x86_64 architecture. It's not compatible with arm64 portaudio, in this case, make sure to include arch -arm64 in front of pip to build the correct binary.
TIP #3
Use an older version of python, I personally used version 3.6.
Oh, and make sure the single quote is actually ' if you copied the command from a text editor.
Hope this helps!
first you need to download portaudio using homebrew
brew install portaudio
Then try to install pyaudio directly
pip install pyaudio
if you are getting error while installing follow below step
Or
if you are facing any error mentioned bellow you can follow these steps
error 1
option 'include_dirs' in section 'build_ext' already exists
error 2
Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects
error 3
#include "portaudio.h"
^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
solution start here
after installing homebrew you have to link it
brew link portaudio
in some cases it will say that it has been already linked then simply ignore
we need path of portaudio where it is exactly installed
brew --prefix portaudio
it will gives you path of portaudio
then you have to check if pydistutils.cfg file exists or not
sudo cat $HOME/.pydistutils.cfg
if file exists then it will open else create it will below command
sudo cat $HOME/.pydistutils.cfg
so in these file we have to define proper path here
[build_ext]
include_dirs=/--PATH--/include/
library_dirs=/--PATH--/lib/
you can get that path by running below command
brew --prefix portaudio
if that path is not working then try below path
[build_ext]
include_dirs=/Users/<username>/homebrew/Cellar/portaudio/19.20140130/include/
library_dirs=/Users/<username>/homebrew/Cellar/portaudio/19.20140130/lib/
If you use mac os
Install Homebrew (insert link into the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" )
Insert command into the terminal:
brew install portaudio
Insert command into the terminal:
pip install pyaudio
p.s. sometimes you need upgrade your pip installer
These actions solved my problem (mac os Mojave 10.14.4)

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

pytables installation failed

I do:
sudo pip install --upgrade tables
I get:
/usr/bin/ld: cannot find -lhdf5
collect2: ld returned 1 exit status
.. ERROR:: Could not find a local HDF5 installation.
You may need to explicitly state where your local HDF5 headers and
library can be found by setting the ``HDF5_DIR`` environment
variable or by using the ``--hdf5`` command-line option.
Complete output from command python setup.py egg_info:
/usr/bin/ld: cannot find -lhdf5
however:
$ echo $HDF5_DIR
/opt/hdf5/
$ ls /opt/hdf5/
bin include lib share
$ ls /opt/hdf5/lib/
libhdf5.a libhdf5_hl.la libhdf5_hl.so.8 libhdf5.la libhdf5.so libhdf5.so.8.0.1
libhdf5_hl.a libhdf5_hl.so libhdf5_hl.so.8.0.1 libhdf5.settings libhdf5.so.8
What's wrong? How to debug? I already tried to set HDF5_DIR to /opt/ or to /opt/hdf5/lib.
I also had the same error on Debian sid trying to work in a local virtualenv. To work around it I did:
apt-get build-dep python-tables
HDF5_DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial/ && pip install tables
... now it's working.
I was able to fix this easily in OSX with virtual environments using the following code:
$ brew install hdf5
$ pyvenv test
$ workon myvenv # to get pytables working within the virtual environment myvenv
$ pip install numpy numexpr cython
$ pip install tables
(taken from andreabedini post in https://github.com/PyTables/PyTables/issues/385)
I'm having a similar problem, but I'm using the leading edge not the pip release (see Aside).
I also tried pointing to the library itself
export HDF5_DIR=/usr/lib/libhdf5.so.6
but it did not work.
Aside: You can try the leading edge of PyTables if you think your bug may have been addressed recently:
sudo pip install git+https://github.com/PyTables/PyTables
.
The build (that was caused by pip install...) seemed to progress further after I installed the dev version of the hdf5 library (libhdf5-openmpi-dev). The build still failed for other reasons, but it's another direction you could try.
Perhaps you can install the stable wheel file for your os for pytables from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pytables
Use this command to check for which file to download
path/to/pythonX.Y -m pip debug --verbose
And this command to install the wheel file
pip install C:/some-dir/some-file.whl
I tried everything without success. The only way I could I achieved was using nehalecky's answer I got here:
https://github.com/PyTables/PyTables/issues/219
In a nutshell, you should do these 2 commands, correcting the path, of course:
sudo python3 setup.py build_ext --inplace --hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial/
sudo python3 setup.py install --hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial/
Hope it helps!

OS X Mountain Lion: gcc-4.2 No such file or directory

Tried to install a gem on Mountain Lion and make couldn't find gcc-4.2:
kamil$ gem install posix-spawn -v '0.3.6'
Building native extensions. This could take a while...
ERROR: Error installing posix-spawn:
ERROR: Failed to build gem native extension.
/Users/kamil/.rbenv/versions/1.9.3-p0/bin/ruby extconf.rb
creating Makefile
make
compiling posix-spawn.c
make: gcc-4.2: No such file or directory
make: *** [posix-spawn.o] Error 1
If you have Xcode installed, gcc should be available. Check where it is with:
kamil$ which gcc
/usr/bin/gcc
Then make a user-land symbolic link from gcc-4.2 to plain gcc:
kamil$ sudo ln -s ~/bin/gcc /usr/bin/gcc-4.2
(Ensure the user-land bind folder is in your path via export PATH=...:$HOME/bin in your .bash_profile or .zshrc.)
Gem installed fine afterwards.
Install simply apple-gcc42 with brew. It generate gcc-4.2 .
brew install apple-gcc42
So we do not need symlinks, which apple update may remove.
Homebrew
As #Artur Bodera mentioned modern OSX will refuse to let you create the symlink in the systems /bin folder.
To avoid this simply create the symlink to your users bin folder
ln -s ~/bin/gcc /usr/bin/gcc-4.2
Don't forget to add the bin folder to your .zshrc or .bash_profile - e.g.
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$HOME/bin
I had a similar issue while installing a python pip package (building a wheel failed). I got the similar message:
unable to execute '/usr/bin/gcc-4.2': No such file or directory
error: command '/usr/bin/gcc-4.2' failed with exit status 1
Linking /usr/bin/gcc-4.2 to /usr/bin/gcc was not possible due to Apples System Integrity Protection (SIP), and linking it to /usr/local/bin/gcc-4.2 was not picked up by the wheel building process; it was still trying to use /usr/bin/gcc-4.2.
I was finally able to solve this by setting the CC variable in the terminal:
CC=/usr/bin/gcc
# Install your packages
pip install -r requirements.txt
PS : note that disabling SIP doesn't work, even with SIP disabled I wasn't able to create the /usr/bin/gcc-4.2 link.

Resources