Im trying to install lxml within a virtualenv with sudo pip install lxml and also sudo pip install --upgrade lxml but getting the following in both cases:
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,
relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes
-D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat
-Werror=format-security build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -lxslt
-lexslt -lxml2 -lz -lm -o build/lib.linux-x86_64-2.7/lxml/etree.so
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools,
tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';
exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'),
__file__, 'exec'))" install --record /tmp/pip-nmFOYf-record/install-record.txt
--single-version-externally-managed --compile failed with error code 1 in
/tmp/pip_build_root/lxml
Storing debug log for failure in /root/.pip/pip.log
I have tried all the posted solutions here, which implies that I have libxml2-dev, libxslt-dev and python-dev installed and I also installed build-essential
I'm currently running Linux Mint 17 Debian Based which uses apt-get as package manager.
python-lxml was already preinstalled.
lxml depends on various C libraries, and you have to have those C libraries installed—including their development files (headers, .so or .a libraries, etc.)—to build lxml. The installation docs explain what prerequisites you need to build on your particular platform.
This error:
/usr/bin/ld: cannot find -lz
… means that the prerequisite you're missing is libz, aka zlib.
Since you're not on Windows, it's incredibly unlikely that you actually don't have zlib at all… but pretty plausible that you don't have the development files for zlib. On some platforms, most notably many linux distros, packages are typically split into separate pieces. For example, the parts of zlib needed at runtime may be in a package named zlib, while the parts needed for building other programs that need zlib in a package named zlib-dev or zlib-devel. The exact details depend on your exact platform.
That being said, if you don't have the zlib development files, you probably don't have the libxml2 or libxslt development files either, because I don't know of any platform where installing those wouldn't have pulled in the zlib files as well.
At any rate, since you haven't told us what platform you're one (and distro, if linux), I don't know what package manager to use, what the packages are named, etc., but do whatever's appropriate for your platform.
Also:
I already have python-lxml installed
You really shouldn't install the same package both with your distro's package manager and with pip; that's a great way to confuse yourself.
But at any rate, most likely you installed python-lxml from a binary package, not from source, which means you didn't need the build requirements. Now you're trying to build it from source, which means you do.
On an ubuntu based linux distro you can use:
sudo apt-get install zlib1g-dev
Related
I'm having a mess of problems trying to install python modules with pip using a local version of python/pip installed in my home directory. First, this should prove my PATH variable is set correctly:
command -v python
/home/myuserid/PYTHON4/bin/python
command -v python
/home/myuserid/PYTHON4/bin/pip
I then try to install python modules with pip. Some modules install successfully. But one named matlabplot is giving me problems. Specifically, I run
pip install matplotlib --target=/home/myuserid/PYTHON4/PYTHON
The errors are
Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-VwF2LG/subprocess32/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-pj2g8u-record/install-record.txt --single-version-externally-managed --compile --home=/tmp/tmplDhrIG:
....
gcc -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c _posixsubprocess.c -o build/temp.linux-x86_64-2.7/_posixsubprocess.o
_posixsubprocess.c:16:10: fatal error: Python.h: No such file or directory
#include "Python.h"
There are two problems with that error message:
First, it is using /usr/local/bin/python. This is the wrong python (I previously installed python there). Where is that coming from? It's not on my path. If I print my entire environment with printenv, it's not listed anywhere.
Second, the gcc compile command explictly includes "-I/usr/include/python2.7" on the command line. That should not happen because I'm trying to use a local python that is installed in/p/home/myuserid/PYTHON4.
I'm guessing the cause is I'm somehow not specifying where python is installed. How can I fix these problems?
Avoid pip install, prefer python -m pip install. This way you're telling explicitly you want to use the python program for which you checked the path. And you can play many variations around it:
python3 -m pip install
/usr/bin/python3 -m pip install
python3.9 -m pip install
...
About the numpy issue, it's because pip don't find an already compiled numpy for your platform. It may be because you're running an old version or pip, so you can first try a python -m pip install --upgrade pip, and try installing numpy again.
You can also take a look at https://pypi.org/simple/numpy, you'll see a list of files like:
numpy-1.21.2-cp38-cp38-win_amd64.whl
numpy-1.21.2-cp39-cp39-macosx_11_0_arm64.whl
numpy-1.21.2-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl
the whl files are pre-compiled ones, but for specific platforms and specific Python versions, here the 3 wheels I listed are for numpy 2.21.2, for cpython 3.9, for windows, macosx, and many linuxes.
Maybe your specific set of Python version / numpy version / platform is not pre-compiled here?
If you really need to let pip compile numpy you'll need some more dependencies, the missing Python.h one means you're missing the python3-dev package from your distrib.
Last hint: you should use a venv: a venv is created by a specific version of Python, and all installations are done inside the venv (so easily removable: just remove the directory, in case it goes badly).
I am running mysql#8.x version on my MacOS, I have installed mysql and mysql-connector-o with brew. Currently brew link with mysql.
Running Django project on my python3 virtual env I am receiving following error -
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?
and on installing the mysqlclient using pip, I am reciving following error
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/local/Cellar/mysql/8.0.12/include/mysql -I/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _mysql.c -o build/temp.macosx-10.13-x86_64-3.6/_mysql.o
clang -bundle -undefined dynamic_lookup -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk build/temp.macosx-10.13-x86_64-3.6/_mysql.o -L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-x86_64-3.6/_mysql.cpython-36m-darwin.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
----------------------------------------
Command "/Volumes/Samsung_T5/Work/python/repos/venv3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-kf2fkhtc/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-qwpjjw3e/install-record.txt --single-version-externally-managed --compile --install-headers /Volumes/Samsung_T5/Work/python/repos/venv3/bin/../include/site/python3.6/mysqlclient" failed with error code 1 in /private/tmp/pip-install-kf2fkhtc/mysqlclient/
As jordanm pointed it out, the issue was exactly with the missing openssl libraries, for which I followed these steps to fix my issue -
Installing openssl
brew install openssl
Now
pip install mysqlclient should work.
If it doesn't and still shows the same error library not found for -lssl, you could also try to link against brew's openssl:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient
if this still does not work, you might need to use the --no-cache option of pip, e.g.
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install mysqlclient
After installing openssl via Homebrew I placed
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
in my .bash_profile and ran
source .bash_profile
and then
pip install mysqlclient
I need to install scipy. However, after about 5-7minutes of compilation time I am getting the follwing error on Ubuntu 14.04.3 LTS:
sudo pip3 install scipy
...
error: Command "x86_64-linux-gnu-g++ -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -D__STDC_FORMAT_MACROS=1 -Iscipy/sparse/sparsetools -I/usr/local/lib/python3.4/dist-packages/numpy/core/include -I/usr/include/python3.4m -c scipy/sparse/sparsetools/csc.cxx -o build/temp.linux-x86_64-3.4/scipy/sparse/sparsetools/csc.o" failed with exit status 4
In file included from /usr/local/lib/python3.4/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0,
from /usr/local/lib/python3.4/dist-packages/numpy/core/include/numpy/ndarrayobject.h:18,
from scipy/sparse/sparsetools/sparsetools.h:5,
from scipy/sparse/sparsetools/csc.cxx:4:
/usr/local/lib/python3.4/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by " \
^
x86_64-linux-gnu-g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
----------------------------------------
Cleaning up...
Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/scipy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-e3q7ek8f-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/scipy
Storing debug log for failure in /home/ubuntu/.pip/pip.log
Does anybody have an idea how to fix this?
It seems your numpy was installed using the distro package manager (i.e. by running apt-get install python3-numpy) since the numpy package is in the dist-packages directory of your python libs. Why don't you install scipy this way too? You can just run
sudo apt-get install python3-scipy
If you want to use pip, I suggest installing packages in virtualenv instances (or, even better, virtualenvwrapper) so that you avoid such conflicts. Otherwise, you should be using a systemwide version of pip, rather than a user installed one (the output says your pip belongs to user ubuntu), so you could first install it using apt-get and then make sure to use this new pip to install scipy.
Installing setuptools made it work for me on ubuntu 14.04
I am using openpyxl python package in my application. I am getting the following message when using the same.
/usr/local/lib/python2.7/dist-packages/openpyxl/init.py:31:
UserWarning: The installed version of lxml is too old to be used with
openpyxl
warnings.warn("The installed version of lxml is too old to be used with openpyxl")
Openpyxl requires lxml version 3.2.5 or above, and the version in my machine is 3.2.0. When I try to upgrade lxml to the latest version ie
3.3.5, it is getting interrupted with the following message.
i686-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.linux-i686-2.7/lxml/etree.so
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
error: command 'i686-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Rolling back uninstall of lxml
Replacing /usr/lib/python2.7/dist-packages/lxml
Replacing /usr/lib/python2.7/dist-packages/lxml-3.2.0.egg-info
Cleaning up...
Removing temporary dir /tmp/pip_build_root...
Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ov0PUy-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/lxml
I need help in resolving the issue.
PS:- I have already installed lxml dependent packages python-dev, libxml2-dev and libxslt1-dev in my machine.
sudo pip install --upgrade lxml
On Ubuntu (and other Debian derivatives), before you build some piece of software, ensure that its build dependencies are installed. Using your example, run this:
sudo apt-get build-dep python-lxml
That is likely going to require a whole bunch of packages, one of which is zlib1g-dev, as mentioned.
I think what you're missing is zlib1g-dev.
sudo apt-get install zlib1g-dev
Running above command will solve the issue.
I'm having a ton of trouble installing modules. At first I thought I had messed with my python installation on mac os x but I installed a virtual machine and ubuntu 11.04 and have similar troubles. Why are both os x and ubuntu failing with the same error?
For example I can't install tkinter with it failing:
Installing collected packages: tkinter-pypy
Running setup.py install for tkinter-pypy
building '_tkinter' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DWITH_APPINIT -I/usr/include/tcl -I/usr/include/tk -I/usr/include/python2.7 -c src/_tkinter.c -o build/temp.linux-i686-2.7/src/_tkinter.o
src/_tkinter.c:74:17: fatal error: tcl.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/pfm/build/tkinter-pypy/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-sMB5Wi-record/install-record.txt:
running install
running build
running build_ext
building '_tkinter' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DWITH_APPINIT -I/usr/include/tcl -I/usr/include/tk -I/usr/include/python2.7 -c src/_tkinter.c -o build/temp.linux-i686-2.7/src/_tkinter.o
src/_tkinter.c:74:17: fatal error: tcl.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/pfm/build/tkinter-pypy/setup.py';execfile(__file__)" install --single-version-externally-managed --record /tmp/pip-sMB5Wi-record/install-record.txt failed with error code 1
Storing complete log in /home/pfm/.pip/pip.log
I encountered exactly the same problem when trying to install tkinter-pypy on Ubuntu 11.04. The error message shows that it's looking for tcl.h file in /usr/include/tcl, but it's not there. I have to install the dev version of the tcl library (I installed tcl8.4-dev).
sudo apt-get install tcl8.4-dev
This installs the header files to /usr/include/tcl8.4. I then created a symlink /usr/include/tcl pointing to that. I also installed the dev version of the tk library (e.g. tk8.4-dev) which installed the tk.h header (needed too by tkinter-pypy) in the /usr/include/tcl directory.
After these steps, tkinter-pypy can be installed successfully.
Not sure about the error, but Tkinter should be available with your Python install. Have you tried to import Tkinter. On a related note I'd definitely recommend using setuptools (aka. easy_install) or one of the other similar installation tools.
EDIT
If Tkinter is still not available, then, on Linux, try locate lib-tk and adding it to your python path
import sys;
sys.path.append(PATH_TO_TK)
Then check out the Wiki to get the setup to stick: http://wiki.python.org/moin/TkInter
Another EDIT
A simple work around might be to install IDLE, which depends on Tkinter (noted by the OP).