import pygtk works but not import gtk - python-2.7

I am configuring pygtk in my centos 5.4 machine. But I am facing few issues.
I want pygtk to be configured to Python 2.7(The default python version is Python 2.4 in centos 5)
So I installed Python 2.7 with different --prefix to my local space and then installed pygobject2.28 and then pygtk2.24 with the --prefix="where python 2.7 installed".
But when I run python2.7 interpreter I am able to import pygtk but, when I try to import gtk it says "no module named gtk."
I have configured PYTHONPATH and PYTHON environment variables to python2.7/lib/site-packages and python2.7 respectively.
My questions:
if pygtk is a wrapper for gtk then why am not able to import gtk, when I am able to import pygtk.
Where does python(or pygtk) pick the gtk from?
And how can I solve the above problem!?
I tried google and other stack overflow questions. But none of them answered the above quesions.

I wasn't checking the ./configure output properly. The problem was, I was trying to install gtk and pygtk without installing cairo and pango. So pygtk skipped building gtk packages because it did not find any cairo package. This was mentioned in the ./ configure script but I had not checked that.
Summarizing:
To configure pygtk to python need to folow these steps
install sqlite-devel #If sqlite needed
install python(2.7)
install gtk(2.24.0) -> requires glib(2.27.3), atk(1.29.2), cairo(1.8.10), pango(1.22.4), gdk-pixbuf(2.21.3)
install pygtk(2.24.0) -> requires pygobject-2.28.3, pycairo(1.8.10)
All the above packages must be compiled to the same prefix, and need to set the PYTHON and PATHONPATH environment variables. The versions of packages also play major role. Added version in parenthesis that worked for me.
There are many dependencies while installing some of the packages so I had to install following packages using yum: libxext, librender, gettext, zlib, libgtk2-devel

Related

Python 2.7 Opencv error, ImportError: DLL load failed: The specified module could not be found

Working on python 2.7(not anaconda). Operating system Windows server 2012 R2
The pypi installation mentions two fixes for this, installing Visual C++ redistributable 2015 and Universal C Runtime.
As well as a manual fix for older anaconda versions, which is for python3(I am not using anaconda version, and also my python version is 2.7 so presuming it doesn't apply in my case)
link here:
https://pypi.org/project/opencv-python/
installed both the dependencies but couldn't get it to work.
Any ideas on how I may fix this?
Since Python 2.7 is still supported, this could be the possible solution.
Installing OpenCV from prebuilt binaries:
Below Python packages are to be downloaded and installed to their default locations.
Python-2.7.x
Numpy
Matplotlib
Install all packages into their default locations. Python will be installed to C:/Python27/.
After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.
Download latest OpenCV release and install it : Latest OpenCV-build
Goto opencv/build/python/2.7 folder.
Copy cv2.pyd to C:/Python27/lib/site-packeges.
Open Python IDLE and type following codes in Python terminal.
import cv2
print cv2.__version__

How to install GDAL/scipy using cmd in window?

I downloaded scipy-0.17.0-cp27-none-win_amd64.whl and GDAL-1.11.4-cp27-none-win_amd64.whl from gohlke in C:\Python27\Scripts
To install I used
pip install scipy-0.17.0-cp27-none-win_amd64.whl
pip install GDAL-1.11.4-cp27-none-win_amd64.whl
It says the installation is complete but when I import the libraries as
import scipy
import gdal
it shows error as
No module named gdal
No module named gdal
However, I installed the matplotlib, numpy in the very same way and they are working absolutely fine.
I solved this problem eventually to found the mistake in my approach.
This problem can occur with anyone using ArcGIS in one's system.
ArcGIS comes with it's default Python package and if one installs python separately, each time the new libraries gets installed in the newer Python installation not in ArcGIS.
Therefore, the pyhton IDLE which one uses need to be from another Python installation.
Here in my case, ArcGIS has Python 2.6 and I have made an separate installation using Python 2.7.11.
All the libraries were getting installed in right place but I was opening the wrong IDLE to write scripts hence getting error.

Python (Win 10): Installing matplotlib requires packages "freetype" and "png"?

I've been trying to install Python's matplotlib library for use with PyPlot, for use with Julia. I managed to get everything in place except for this one final library, and I feel as though I've hit a deadend trying to get it working.
When trying to install matplotlib (I've attempted using pip, regular python install, and easy_install), I get the following message at the very end of the install output, after which it is NOT installed:
* The following required packages can not be built:
* freetype, png
Confused about this, I looked around online and installed both of these (at least, what I think these were). One was the freetype project, and the other was LibPng, which was the closest thing I could find to a "png package" for windows or python in general.
This didn't initially work (for either of them), and I read somewhere that I needed a freetype.dll in my system32 folder. It was a long shot, but I went to where I installed freetype and pulled out the dll and renamed it, placing it in system32. This of course did not work (again, long shot).
Anyway, that's where I'm at. No idea where to go from here, and I'm unsure if I even grabbed the correct "packages" I should be using. Thoughts?
Use a more powerful installer
I would recommend to use Anaconda or Miniconda. In my experience with many Windows users, this is the simplest way to install packages such as matplotlib.
Anaconda
Anaconda comes with many packages for scientists. Matplotlib works out of the box. Just install as user not root.
Minoconda
If you don't want all packages of Ananconda use Miniconda
Conda
Both ways of installation (Anaconda or Miniconda) provide conda. It is an improved pip/virtualenv.
You can install matplotilb with this command:
conda install matplotlib
Enviroments:
You can create a new environment and install the packages you like:
conda create -n my_project35 python=3.5
activate my_project35
conda install matplotlib
or
conda create -n my_project27 python=2.7
activate my_project27
conda install matplotlib
Combine with pip
You can still use pip. conda "understands" what it is doing.
One snake is enough!
[This is for folks using the Linux Bash Shell on Windows 10.]
If you don't want to go the Anaconda route, you can install freetype (and png) by executing the following in the Windows 10 Bash shell:
sudo apt-get install freetype6-dev
The above command will also automatically install libpng. However, due to an error, the system will not 'realize' it has installed freetype, so you'll need to manually install pkg-config:
sudo apt-get install pkg-config
Thereafter you should be able to install matplotlib via pip without further incident.
sudo pip install matplotlib
I tired downloading matplotlib 2.2.2 with python 3.9.5, getting freetype & png errors for hours.
After downloading python 3.7.9 and removing python 3.9.5 from environment variables, installing matplotlib 2.2.2 worked with no problems!
Change your Python Version
Go to https://www.python.org/downloads/windows/, control-f search 3.7.9 and use the webinstaller. Follow all the recommended instructions
In pyvenv.cfg in your project directory switch version number to 3.7.9 and home to C:.....\Python37.
pip3 install alpaca-backtrader-api

lapack/blas-related error when trying to add scipy to miniconda-installed copy of python 2.7.10 on RedHat 6

I have two versions of python on my RedHat 6 machine: 2.7.8 that came with the system originally and 2.7.10 that I've installed using miniconda for a project. I have to use the newer version to run some demo code for another project. The demo script produced this error:
ImportError: No module named scipy.sparse
Running pip install scipy failed with a bunch of warnings and then this:
numpy.distutils.system_info.NotFoundError: no lapack/blas resources found
numpy is already installed. That is, I get Requirement already satisfied when trying to pip install numpy.
The yum install command recommended on the SciPy install page completed fine but did not help, probably because this python version is installed at a non-default location.
Same result after building blas and lapack from source as described here
How do I get scipy to install properly?
Thx
I think you don't have lapack/blas library.
try this.
yum install python-devel python-nose python-setuptools gcc gcc-gfortran gcc-c++ blas-devel lapack-devel atlas-devel
it will install all what you need.
If you use Anaconda/miniconda, then use the conda package manager, not pip:
conda install scipy.
Value of a Peace of mind once starting always from a [Defined state]
There are many issues with pip / yum installer strategies that we, mortals, can spend ages on our attempts to get resolved.
Since I started to use the Travis Oliphant's Anaconda fully-fledged package-manager, these dependency-related / version-colliding issues simply disappeared. Well did not disappear, but principally do not appear.
Why?
Anaconda package-manager both allows one to keep separate versions ready / reconfigurable via Anaconda for individual python launches
and
Anaconda resolves updates in a smart way, one would never experience with manual/semi-manual pip/yum installers
In other words, if you strive to get rid of issues, opt to install Anaconda and start using it's (parallel) multi-versions installation / setup controls and it's smart package-manager facilities.
n.b.: this is not a commercial/spam/PR, this is just personal experience after many years of troubles with individual package updates' collisions / compatibility back-testing troubles in multi-py 2.5 / 2.6 / 2.7 installations environments

too many pythons on linux

i recently started using python with xubuntu on virtualbox but i'm having problems. I want to be able to use numpy so i thought that apt-get install python-numpy would solve everything, but using the shell i kept getting No module named numpy. I used IDLE and it could find it. I also have IDLE (using Python-2.7), and again it could import numpy. Then i noticed that the shell had python 2.7.9, while the IDLEs had python 2.7.6.
Using
import sys
print sys.path
this if what i get from 2.7.9 (shell)
/usr/local/lib/python2.7/site-packages/setuptools-17.0-py2.7.egg
/usr/local/lib/python2.7/site-packages/Pillow-2.3.0-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
and from 2.7.6 (IDLE)
/home/alessandro
/usr/bin
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/PILcompat
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.7
/usr/lib/python2.7/dist-packages/ubuntu-sso-client
I understand that i have two versions of python installed and somehow i ended up installing packageg into only one of them (the 2.7.6).
I'd like to be able to use 2.7.9 both in the shell and in IDLE and also i'd like to install so that python 2.7.9 can see them.
I read that i can add paths to the python sys.path, but isn't there a more efficient/persistent way to do what i want?
PS: tell me if you need more informations
For my projects I usually create a virtualenv for each python version I need for the project at hand. I manage them using pip to install specific versions that I need. Moreover you should be able to choose the python path in your IDE. While I'm not using IDLE, I read here that apparently idle comes along with the python versions during install. So maybe your idle versions collide with each other. If you want to have only one python version at the time on your machine you might consider a simple remove and fresh install of your desired version. Again I would recommend pip over apt-get etc. Hope this is of help for you.
Worth to check PyDev, a plugin for Eclipse to work on python.
http://marketplace.eclipse.org/content/pydev-python-ide-eclipse , or http://pydev.org/.
This allows you to configure the python version for different project's.
I have some project's with python 2.7 and others with 3.4.
it's checks the whole system in search for the PYTHONPATH to use!