Installing matplotlib on RedHat ideally using yum - python

I can't seem to find documentation on this. Matplotlib says to run:
sudo yum install python-matplotlib
which installs all the dependancies and this version of matplotlib successfully:
python-matplotlib.x86_64 0:0.99.1.2-1.6.amzn1
However, I use python2.7, separately installed. The original (and still existing) python2.6 now imports matplotlib successfully. Is there a related matplotlib package on RedHat for python2.7? I don't know how to use this page on python-matplotlib packages.
Other info:
which python2.6 returns /usr/bin/python2.6
which python returns /usr/bin/python.
cat /proc/version returns
Linux version 3.14.23-22.44.amzn1.x86_64 ... (Red Hat 4.8.2-16) (GCC) ...
Something else I tried:
I also tried to use pip2.7 instead, installed all the dependancies, and it broke on this issue concerning permissions. The solution is to reset the permissions of the problem file with:
chmod o+x /path/to/file
However, it's a temporary copied file. :( During the install of matplotlib it recopies this file over, so I can't set permissions on it. Here is the place it is broken:
g++ ... -lpython2.7 -o build/lib.linux-x86_64-2.7/matplotlib/backends/_backend_agg.so
running install_lib
copying pylab.py -> /usr/lib64/python2.7/site-packages
error: [Errno 13] Permission denied: '/usr/lib64/python2.7/site-packages/pylab.py'
This doesn't seem like the right way to do it, it's too cobbled together.
Question asked first at the Unix&Linux stackexchange.

I built from source. :( Surprisingly not that difficult, but ran into a lot of problems doing the interactive part (Redhat 4 is too old to have packages for most things that let you do interactive backends, I need a newer machine).
# get matplotlib
wget https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.4.3/matplotlib-1.4.3.tar.gz
#uncompress
tar xvzf matplotlib-1.4.3.tar.gz
# open build install
# read INSTALL file for more instructions
cd matplotlib-1.4.3
python setup.py build
# actually installing needed superuser privileges
sudo python setup.py install
Hope this saves time for anyone else with a similar setup.

On centos 7 I installed python 3.6.1, into /usr/local
This also automatically installed pip
Then I ran sudo /usr/local/bin/pip3.6 install matplotlib
and it was all good

Related

Going nuts: How to get python 3.7.6 installed on CentOS 7

I have tried many ways of installing python3.7.6 on centos 7.
Regardless of what I do, I always get the error that the SSL module is not available.
I have tried basic install guides such as https://tecadmin.net/install-python-3-7-on-centos/
(short story: yum install openssl-devel, configure, make install)
One with manual/updated changes to the build files (https://joshspicer.com/python37-ssl-issue)
I've downloaded and built openssl myself, then tried to configure/build python with --with-openssl
No go.
Any other ideas?
If it were really this hard, no one would be using it, so I must have something special going on.
Ok, here's what finally worked for me.
I think the key to success was updating LD_LIBRARY_PATH and PATH to include openssl as I went.
Install and build openssl.
OpenSSL 1.1.1d 10 Sep 2019
cloned openssl repo
Pulled out latest(?) 1.1 branch
git checkout OpenSSL_1_1_1d -b 1_1_1d
./config --prefix=/opt/openssl
make
make install
Add /opt/openssl/lib to your LD_LIBRARY_PATH env var
Add /opt/openssl/bin to your PATH
Install and build python-3.7.6
I installed with --prefix=/opt/python-3.7.6
./configure --prefix=/opt/python-3.7.6 --enable-optimizations --with-openssl=/opt/openssl
make
make install
Add /opt/python-3.7.6/lib to your LD_LIBRARY_PATH env var
Add /opt/python-3.7.6/bin to your PATH
Final Config
LD_LIBRARY_PATH=/opt/openssl/lib:/opt/python-3.7.6/lib:
PATH=/opt/openssl/bin:/opt/python-3.7.6/bin:/opt/idea/latest/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
seeing your post i decided to stop trying to install 3.7 (already half an hour of head banging) and went for 3.6 using IUS. however, when i checked the version i had just installed, i saw this:
$ python3 -V
Python 3.7.4
so it looks like i got 3.7 even though this is the yum command i used:
$ yum install python36
anyway, it worked for me, perhaps it will work for you? a little bizarre, imo.

Installing 3rd party Python modules on an Ubuntu Linux machine?

I'm guessing my question is pretty basic, but after 15-20 minutes on Google and YouTube, I am still a little fuzzy. I am relatively new to both Linux and Python, so I am having some difficulty comprehending the file system tree (coming from Windows).
From what I've found digging around the directories in Ubuntu (which is version 12.04, I believe, which I am running in VBox), I have ID'd the following two directories related to Python:
/usr/local/lib/python2.7 which contains these two subdirectories:
dist-packages
site-packages
both of which do not show anything when I type "ls" to get a list of the files therein, but show ". .." when I type "ls -a".
/usr/lib/python2.7 which has no site-packages directory but does have a dist-packages directory that contains many files and subdirectories.
So if I want to install a 3rd party Python module, like, say, Mechanize, in which one of the above directories (and which subdirectory), am I supposed to install it in?
Furthermore, I am unclear on the steps to take even after I know where to install it; so far, I have the following planned:
Download the tar.gz (or whatever kind of file the module comes in) from whatever site or server has it
Direct the file to be unzipped in the appropriate subdirectory (one of the 2 listed above)
Test to make sure it works via import mechanize in interactive mode.
Lastly, if I want to replace step number 1 above with a terminal command (something like sudo apt-get), what command would that be, i.e., what command via the terminal would equate to clicking on a download link from a browser to download the desired file?
You aren't supposed to manually install anything.
There are three ways to install Python libraries:
Use apt-get, aptitude or similar utilities.
Use easy_install or pip (install pip first, its not available by default)
If you download some .tar.gz file, unzip it and then type sudo python setup.py install
Manually messing with paths and moving files around is the first step to headaches later. Do not do it.
For completeness I should mention the portable, isolated way; that is to create your own virtual environment for Python.
Run sudo apt-get install python-virtualenv
virtualenv myenv (this creates a new virtual environment. You can freely install packages in here without polluting your system-wide Python libraries. It will add (myenv) to your prompt.)
source myenv/bin/activate (this activates your environment; making sure your shell is pointing to the right place for Python)
pip install _____ (replace __ with whatever you want to install)
Once you are done type deactivate to reset your shell and environment to the default system Python.
virtualenv is the de facto Python standard for installing third party library cleanly. Read more about it here:
http://www.virtualenv.org/
Usage example:
daniel#redhotcar:~/tmp$ virtualenv myenv
New python executable in myenv/bin/python
Installing distribute....................................................................................................................................................................................done.
Installing pip...............done.
daniel#redhotcar:~/tmp$ cd myenv/
daniel#redhotcar:~/tmp/myenv$ bin/pip install mechanize
Downloading/unpacking mechanize
Downloading mechanize-0.2.5.zip (445Kb): 445Kb downloaded
Running setup.py egg_info for package mechanize
Installing collected packages: mechanize
Running setup.py install for mechanize
Successfully installed mechanize
Cleaning up...
daniel#redhotcar:~/tmp/myenv$ bin/python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
>>> mechanize
<module 'mechanize' from '/home/daniel/tmp/myenv/local/lib/python2.7/site-packages/mechanize/__init__.pyc'>
>>>
On Ubuntu, install virtualenv via apt-get install python-virtualenv
You can use
sudo apt-get install python3-library_name
Replace library_name by any other library (e.g. scipy, pandas, numpy, matplotlib, etc.)
use setuptools http://pypi.python.org/pypi/setuptools/
then type
pip install <somePackageName>
or
easy_install <somePackageName>
they will look in the pypi directories (on the interwebs) for the package and will install the correct version for you automagically...
To install nay python package in ubuntu, first run
sudo apt-get update
Then type "sudo apt-get install python-" and press tab twice repeatedly.
press y or yes and it will display all the packages available for python. Then again type
sudo apt-get install python-package
It will install the package from the internet.

python pip install psycopg2 install error

I did a simple pip install psycopg2 on mac system. It installed fine, but when I try to use psycopg2 I get the error:
Reason: Incompatible library version: _psycopg.so requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8
pip freeze shows psycopg2==2.4.5 just right. I have installed psycopg2 on several virtualenvs but this is the first time I am seeing such error. I tried uninstalling and reinstalling, same results. Please help
The accepted answer here is correct (except I think it must be ln -fs , in fact I think it might even risk destabalizing your OS if not (?)). After bumping into this and dealing with it I just want to collect the full solution for this issue and the other lib problem (libcrypto.1.0.0.dylib) you will run into for Postgres 9.* on Mountain Lion and Snow Leopard, and perhaps other systems. This also blocked me from running psql, which complained about the same two libs.
Essentially there are two later-version libs needed in /usr/lib, libssl and libcrypto. You can find the needed versions of these libs in the Postgres lib directory.
If you're OSX and installed the Enterprise DB version of Postgres this will be in /Library/PostgreSQL/9.2/lib.
For other install types of Postgres, look for the lib directory inside the Postgress install directory, e.g., for Postgress.app, find the lib directory in /Applications/Postgres.app/Contents/MacOS/lib,
for brew somewhere in /usr/local/Cellar,
on *nix, wherever your install is. But see first on *nix if your distro has later versions just through the package manager.
First copy the latest of these two libs from the Postgres lib directory to /usr/lib:
sudo cp /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
sudo cp /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib
Then update (or create) the /usr/lib symlinks for this libs. Either way the command is ln -fs:
sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
Should be fixed. Pretty sure ln -fs is better than deleting the symlink and remaking it, so there is less chance of libssl being unfindable by something that needs it for the time it is not present (it does the same thing; it first deletes the symlink if it's already there, just faster than you can type it). Always wary of messing around on /usr/lib.
Worked for me:
env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib
-L/usr/local/opt/readline/lib' pip install psycopg2
Source: Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7
I ran into a similar problem after upgrading to Mountain Lion.
Instead of copying libssl.* files per Slack's suggestion, make sure that /usr/lib/libssl.dylib is actually a soft link to the most up-to-date version of the library.
E.g., on my machine, ls -l /usr/lib/libssl* gives:
lrwxr-xr-x 1 root wheel 46B Jun 27 15:24 /usr/lib/libssl.1.0.0.dylib -> /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
lrwxr-xr-x 1 root wheel 27B Jul 30 10:31 /usr/lib/libssl.dylib -> /usr/lib/libssl.1.0.0.dylib
If libssl.dylib doesn't link to the version that the error version mentions, make sure you have that version of the library, and then make sure /usr/lib/libssl.dylib points to it, and not an older version.
If the link doesn't exist, create it like so
sudo ln -s library_to_link_to link_to_create
using, of course, the proper locations for your machine. For me, this turned out to be:
sudo ln -s /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
Edit:
It seems like some are having trouble with part of my solution. Namely, deleting these important libraries even temporarily causes problems with the operating system.
Per Purrell's answer, make sure you include the -fs flags when you use the ln command, which helps ensure that the libraries don't go missing for a short period of time. E.g.,
sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
On OSX 10.11, El Capitan, solution with replacing symlinks reported Operation not permitted. Solution that worked for me was using brew and setting up DYLD_LIBRARY_PATH. So:
brew install openssl
Find where openssl brew libs are located (brew --prefix openssl can help), start searching from directory /usr/local/Cellar/openssl. In my case it is in /usr/local/Cellar/openssl/1.0.2d_1/lib
Finally set up DYLD_LIBRARY_PATH, i.e. add a line like this into .bash_profile :
# replace location of lib files with folder name you found in previous step
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/Cellar/openssl/1.0.2d_1/lib
UPDATE: More generic/better alternatives are (thanks to #dfrankow):
to use brew to find openssl location (a note, brew can be slow): DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(brew --prefix openssl)/lib
for development purposes maybe it is better to use DYLD_FALLBACK_LIBRARY_PATH instead - check this
Restart shell, or just source ~/.bash_profile, reinstall psycopg2:
pip uninstall psycopg2
pip install psycopg2
and test if it works:
$ python -c"import psycopg2 ; print('psycopg2 is now ok')"
When trying to do a syncdb Postgres 9.1 and /psycopg2/_psycopg.so added a further error:
Library not loaded: #loader_path/../lib/libcrypto.dylib
Referenced from: /usr/lib/libpq.5.dylib
Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libcrypto.0.9.8.dylib provides version 0.9.8
Solved by copying these six (6) files from:
LOCAL:/Library/PostgreSQL/9.1/lib/
libssl.1.0.0.dylib
libssl.a
libssl.dylib
libcrypto.1.0.0.dylib
libcrypto.a
libcrypto.dylib
to: LOCAL:/usr/lib
This was on Mac OSx 10.8.1 with a web in a virtualenv (1.8.2) and pgAdmin (1.14.3). Inside the virtualenv is:
Django==1.4
psycopg2==2.4.5
... etc... and now back to normal.
For me, the libcryto and libss version 1.0.0 resides below:
/Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib
/Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
so the commands that fix my problem is:
sudo ln -fs /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
my friend, just copy libssl.* files from PostgreSQL lib directory to /usr/lib and relaunch your application in this case all things will be perfect ^_^
For me on Mavericks, it worked to just copy the two dylib and relaunch Python:
cp /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib /usr/lib/
cp /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib /usr/lib/
If you are uncomfortable copying libraries into your system directory, you can use the DYLD_LIBRARY_PATH environment variable to force the OS to search Postgres's library directory for libssl. E.g.:
$ DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.4/lib pip install psycopg2
(documented under the dyld man page).
I had similar problem on my Mac OS High Sierra.
ImportError: dlopen(/Users/chicha/Projects/CTMR/sample_registration/romans_env/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: /opt/local/lib/libssl.1.0.0.dylib
But after "pip install postgres" it's work fine.
According to pip show - "postgres is a high-value abstraction over psycopg2".
While installing it's also installed psycopg2-binary and psycopg2-pool.
So, all together they have repaired the situation somehow.

How to compile pygtk from source for python2.6 on ubuntu 12.04

I have a application which is stuck at python2.6. I cannot port it to python2.7 due to specific and complicated extensions.
The probleme is that 12.04 removes pygtk for python2.6 as python2.7 becomes the default python version.
I need then to build pygtk for python2.6 from source. I have followed the readme but I am doing something wrong. (the doc is quite succinct)
The build looks ok, as I can import gtk if I am in the decompressed archive folder (I do a python -c 'import gtk').
But the make install doesn't work properly.
AFAICT, I have export'ed PYTHON & PYTHONPATH variables to the proper path.
PYTHONPATH=/usr/lib/python2.6/dist-packages
PYTHON=/usr/bin/python2.6
Any idea on what's wrong with this config ?
I don't know if I'm getting farther than you are, but here's what I'm doing so far. Maybe we can figure this out together.
$ sudo su
# pip install pygtk
This generates a bunch of errors, including "To build PyGTK in a supported way, read the INSTALL file." After reading that and other things, I tried this:
# cd build/pygtk
# chmod 755 configure
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
This finds the right version of Python, but now can't find GLIB. Errors include, "This usually means GLIB is incorrectly installed." When I look in config.log I find this error, "fatal error: glib.h: No such file or directory". I found a help page that suggested you might get this error if you haven't installed a development version of GLIB.
# apt-get install libglib2.0-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
Progress! I now see a new error, "No package 'pygobject-2.0' found". That error appears in a forum post with a suggestion to install python-gobject-dev.
# apt-get install python-gobject-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
No errors, so I try running make and make install. The first one works, but the install fails with an error, "/bin/bash: line 16: ../py-compile: Permission denied". Permission denied is weird when running as root. After flailing for a while, I go back to the output of the configure script and see a message, "checking for PYCAIRO... no", followed by another, "not checking for gtk due to missing pycairo". A little guesswork leads me to install another module.
# apt-get install python-cairo-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
That solves the pycairo complaint, but there are a bunch more, including GTK.
# apt-get install python-gtk2-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
That solved most of the complaints, just LIBGLADE is missing.
# apt-get install libglade2-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
OK, all the modules will be built, but it says, "Numpy support: no".
# make
# make install
This fails with the same error I saw earlier, "/bin/bash: line 16: ../py-compile: Permission denied".
I'm going to leave it here for now and come back to it later.
Try to use easy_install for 2.6, suppose in your ubuntu you have 2.6 and 2.7 installed. you can have easy_install (by default for 2.7), and easy_install-2.6 to install the dedicated packages for 2.6.

How to properly install Python on OSX for use with OpenCV?

I spent the past couple of days trying to get opencv to work with my Python 2.7 install. I kept getting an error saying that opencv module was not found whenever I try "import cv".
I then decided to try installing opencv using Macports, but that didn't work.
Next, I tried Homebrew, but that didn't work either.
Eventually, I discovered I should modify the PYTHONPATH as such:
export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
My problem is that I didn't find /usr/local/lib/python2.*...etc
The folder simply doesn't exist
So my question is this:
How do I properly install Python on OS X Snow Leopard for it to work with opencv?
Thanks a lot,
I spent a couple days on this myself. For me, the problem was that that OpenCV installer was not finding the right python installation. It was defaulting to the MacOS-installed version despite the fact that I had upgraded python with homebrew and was using a virtualenv for python. I have collected most of my setup in a gist here:
https://gist.github.com/4150916
Use homebrew to get all the dependencies, but then download the OpenCV tarball and compile yourself being sure to specify all the python related configuration options.
Assuming a virtualenv named 'opencv'...
cd OpenCV-2.4.3/
mkdir release
cd release
cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
-D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
-D INSTALL_PYTHON_EXAMPLES=ON\
-D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers\
-D PYTHON_LIBRARY=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib\
..
make -j8
make install
You need to install the module using your python2.7 installation. Pointing your PYTHONPATH at stuff installed under 2.6 to run under 2.7 is a Bad Idea.
Depending on how you want to install it, do something like python2.7 setup.py or easy_install-2.7 opencv to install.
fwiw, on OS X the modules are usually installed under /System/Library/Frameworks/Python.framework/ but you should almost never need to know where anything installed in your site packages is physically located; if Python can't find them without help you've installed them wrong.
Installing OpenCV with Homebrew
brew tap homebrew/homebrew-science
brew install opencv
Setting up Python
Depending on your install location - OS X Default
cd /Library/Python/2.7/site-packages/
or - Homebrew Python
cd /usr/local/lib/python2.7
Then create the symbolic link
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so
The above method sourced from a blog post.
I searched and tried installing opencv3 with python3 for 3 days. Some links suggest for Brew and some virtual env, some say install xcode but all failed in my case.
Dont use linux steps to instal opencv-python on Mac. Problem with Mac is Python 2.7 is already installed by Mac. On top of that installing and linking all site-packages is little problematic and we end up with errors.
I'll share what I did: easy steps to install complete package opencv3, numpy, matplotlib, notebook, spyder etc.. on Mac.
Install anaconda, it creates a directory and install everything inside that
use this link -> https://www.continuum.io/downloads
download command-line-install
After download, goto terminal and download location of anaconda.
$ bash Anaconda3-4.3.0-MacOSX-x86_64.sh
Installation will ask you to append path to .bash_profile >> say yes
Goto home directory, run .bash_profile
$ source .bash_profile
check python, should be pointing to
$ which python
$ /.../anaconda/bin/python
Last step
$ pip install opencv-pyhton
$ python
$ import cv2
if no errors, we are good to go.

Categories

Resources