Brew not installing pygtk properly - python

First let me start by giving an example of what happens when I install numpy using HomeBrew
brew install numpy
This successfully dowloads and pours. And now when I try to import in python it works properly.
>>>import numpy
>>>
Now I try to install pygtk through HomeBrew using
brew install pygtk
It successfully Downloads and pours. But when I import it in python I get
>>>import pygtk
Import Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygtk
>>>
Now I went and checked my /usr/local/lib/python2.7/site-packages/
numpy exists but pygtk does not. But pygtk exists in /usr/local/lib/
Why is brew doing this? Also am I getting something fundamentally wrong here?
Now I really don't know what to do exactly but I don't think copying pygtk from /usr/local/lib/ to /usr/local/lib/python2.7/site-packages/
Note: I am using MAC OS and I mainly work through the terminal and would prefer a solution through terminal itself.
Edit1: I have found a solution or rather a workaround.
Basically I am downloading the latest PyGTK.pkg and then installing it. And then copying all the files in the system default python to my python2.7
wget -P /Users/mac_test/Downloads/ https://sourceforge.net/projects/macpkg/files/PyGTK/2.24.0/PyGTK.pkg
installer -pkg /Users/mac_test/Downloads/PyGTK.pkg -target /
cp -r /opt/gtk/lib/python2.7/site-packages/ /usr/local/lib/python2.7/site-packages/
Not sure this is the best way though.

How it worked for me:
First of all I have python installed via brew:
which python && python --version
/usr/local/bin/python
Python 2.7.13
Then I installed pygtk through brew install pygtk and it was successful
After that:
python
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> help(pygtk)
It responds with this:
Help on module pygtk:
NAME
pygtk
FILE
/usr/local/lib/python2.7/site-packages/pygtk.py
So probably copy pygtk to site-packages might solve your issue.
I don't know specific reason you prefer brew over pip + virtualenv but I gently recommend you to try it instead of brew and global library installation.

Related

Ubuntu Python Homebrew no module named '_tkinter'

I have the issue with Python 3.9.1 on freshly installed Ubuntu (Ubuntu 20.04.1 LTS) - when running any tkinter-based application, I get import error (example from python console):
user#ubuntu:~$ python3
Python 3.9.1 (default, Dec 29 2020, 13:25:02)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/linuxbrew/.linuxbrew/Cellar/python#3.9/3.9.1_3/lib/python3.9/tkinter/__init__.py", line 37, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I know this issue was discussed multiple times in SO and other internet resources, for several days I am trying all the options and solutions (like this, this, another one, brew forum neither of them solved the issue).
What works - only uninstalling homebrew does the trick. Still have hope to configure everything to work with homebrew.
What I have tried/performed:
fixed all brew doctor reported issues:
Your system is ready to brew.
tcl-tk is listed under brew list:
black hello libx11 libxdmcp openssl#1.1 pylint sqlite xorgproto
bzip2 libffi libxau libxext patchelf python#3.9 tcl-tk xz
gdbm libpthread-stubs libxcb ncurses pkg-config readline unzip zlib
performed brew uninstall python and brew install python
Initial thought was poetry and/or pyenv broke the dependencies, currently using neither of them.
I am not hardcore ubuntu user, am I missing something? Any idea or help would be valuable.
Homebrew is not the official pcakage mamanger for ubuntu and has some strange behaviours ,Ubuntu's officialy supported pacakage manager that is installed by default is apt(advanced package tool)
First uninstall your brew install of python by typing:
brew uninstall python
Then this is how you use APT to install python3:
sudo apt-get install python3
OR
sudo apt install python3
And to test if python3 installed correctly type:
python3
If a python shell opens python3 has been installed properly
Then to test if tkinter is working type this in the python shell:
import tkinter
Closing the question, as no other activity for over a week.
Used solution I wanted to avoid - removed homebrew, now Tkinter is detected properly.
For anyone stumbling on the same issue - uninstalling homebrew: https://github.com/homebrew/install#uninstall-homebrew

Some Python Versions not Recognizing Installed Packages

I have installed python on my macbook with the python installer from Python.org. Subsequently, I went and installed pip, ipython, and numpy. Everything seemed fine. However, now I am getting the following problem. I can import numpy when I run ipython, but not when I run regular python.
E.g.
Logister-MacBook-Pro:~ Logister$ ipython
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import site; site.getsitepackages()
Out[2]:
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/Library/Python/2.7/site-packages']
However, when I try to do the same thing in python 2.7.9:
Logister-MacBook-Pro:~ Logister$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> import site; site.getsitepackages()
['/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/site-python',
'/Library/Python/2.7/site-packages']
When I try to install numpy via pip it gives me the following response:
Logister-MacBook-Pro:~ Logister$ sudo -H pip install numpy
Requirement already satisfied (use --upgrade to upgrade):
numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
It seems like python 2.7.6 understands where to find numpy, but 2.7.9 does not. Either, how can I point 2.7.9 to the right place, or how can I install numpy so 2.7.9 sees it as well?
Edit: I can run:
site.addsitedir('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
In 2.7.9 and then I am able to import numpy. But I dont want to do this every time I launch 2.7.9. Is there a permanent fix? Also, how do I get ipython to run 2.7.9 instead of 2.7.6?
I had a similar problem.
There is two differences versions of python installed on your computer.
Then you´ve installed numpy on python 2.7.6. but the folder of python 2.7.9 haven't numpy. Do you understand?
Other thing your macOS have a groups of variables called "Environment Variables" there it's identifying the command python with python 2.7.9.
Then if you want to use numpy with the interpreter of python do you need change the Enviroment Variables for the command "python" take the version 2.7.6 or install numpy at python 2.7.9 and work with both versions.
Good luck!
With 2 different version you must have 2 python interpreters on your machine. They are installed on different locations with different libraries. So its just right that you cannot find the module installed on interpreter A while using the interpreter B. The which command can be useful to you to figure out where those interpreter are. You can make a symbolic link manually from a folder to another but it would mess up your mind, and you probably gonna get lost later.
I recommed you to install python and ipython via Homebrew, so it would automatically do all the hard work for you.
Install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Since you said numpy, you are probably looking for scientific stuff so:
# set up some taps and update brew
brew tap homebrew/science # a lot of cool formulae for scientific tools
brew tap homebrew/python # numpy, scipy, matplotlib, ...
brew update && brew upgrade
# install a brewed python
brew install python
Later you can run, but I recommend you to follow this tutorial:
brew install zmq
pip install ipython[all]
I was able to solve the problem by adding the following line to my .bash_profile:
export PYTHONPATH=${PYTHONPATH}:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I then changed the Ipython version by following this stackoverflow question.

I can't call pymongo in the python shell

I'm trying to use pymongo in the IDLE shell on MAC OS X 10.9, but I can only do it in terminal.
when I call import pymongo in IDLE I get the following error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pymongo
ImportError: No module named 'pymongo'
but I use python in terminal I get this:
$ python
Python 2.7.5 (default, Sep 12 2013, 21:33:34)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>>
I can then use it with MongoDB.
Have I made some sort of install error? I'm doing this to learn mongoDB so I'm relatively new to this. Any help is much appreciated.
From the information you supplied in the comments, it appears you have installed a version of Python 3.3.4 on your system but you have installed the PyMongo distribution to an instance of Python 2.7, probably the Apple-supplied system Python 2.7 shipped with OS X 10.9. When you install a third-party package (or "distribution"), it is normally associated only with the Python instance that you used to install it. There are several common ways to install such packages. One way is to use the easy_install command, as is suggested on the PyMongo page. However, the easy_install command is also associated with a particular Python instance. On recent OS X releases, Apple supplies easy_install commands that are associated with and install into the system Pythons. So it's a common pitfall on OS X to install a newer version of Python alongside the system Python but then use the default easy_install command with the result that the package you want ends up installed in the wrong Python version. One solution is to install a separate version of easy_install for each Python version you install. The easy_install command is provided by the setuptools package. However, these days the recommended installer tool for Python is pip which provides more features than easy_install, including the ability to uninstall packages, and is actively supported in the community.
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python3.3 get-pip.py
python3.3 -m pip install pymongo
python3.3 -c "import pymongo; print(pymongo.version)"
-> 2.6.3
You also need to install a version of pip for each Python instance that you use. There are other ways to invoke pip but, by using the way shown above, you know which version of Python you are using and you are less likely to end up with the situation you have now. There are other tools you can use in addition, like virtualenv, but, particularly on OS X, pip should be sufficient to handle most beginning use cases.

WARNING: IPython History requires SQLite, your history will not be saved

Hi I'm using Ubuntu release 12.10 (quantal) 32-bit with Linux Kernel 3.5.0-21-generic. I'm trying to get IPython's History to work. I've set it up using pythonbrew and a virtual environment. In there I use pip to install IPython. Currently, when I start up IPython in a terminal I get:
WARNING: IPython History requires SQLite, your history will not be saved
Python 2.7.3 (default, Nov 8 2012, 18:25:10)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
Searching on the warning in the first line, I found this issue report, so I went back and installed the following:
sudo apt-get install libsqlite0 libsqlite0-dev libsqlite3-0 libsqlite3-dev
and then removed and reinstalled pysqlite using pip
pip uninstall pysqlite
pip install pysqlite
After that I thought I would check the installation by importing the module:
Python 2.7.3 (default, Nov 8 2012, 18:25:10)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
So now it seems the file _sqlite3.so can't be found. That's when I found this SO question. Either it doesn't exist or it's not in my PYTHONPATH environment variable. Searching for the file, I get:
$ locate _sqlite3.so
/home/me/Desktop/.dropbox-dist/_sqlite3.so
/home/me/epd/lib/python2.7/lib-dynload/_sqlite3.so
/usr/lib/python2.7/lib-dynload/_sqlite3.so
So the file is there, but when I looked in my python path:
import sys
for p in sys.path:
print p
none of the above paths that contain _sqlite3.so were contained in my PYTHONPATH. For giggles, I added the path /usr/lib/python2.7/lib-dynload to my PYTHONPATH in a terminal and then tried to import sqlite3 again:
Python 2.7.3 (default, Nov 8 2012, 18:25:10)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("/usr/lib/python2.7/lib-dynload")
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/me/.pythonbrew/pythons/Python-2.7.3/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: /usr/lib/python2.7/lib-dynload/_sqlite3.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8
Uh oh. Now I'm completely stuck. Can anyone help me out? I've also read in a few places that I may have to rebuild Python. I have no idea how to do this in pythonbrew. Can anyone point me in the right direction?
I've also read in a few places that I may have to rebuild Python.
This is correct. SQLite is part of the standard library,
and is built when you compile Python. There are a few 'optional' parts
of the standard library, which Python will simply skip (with minimal warning, unfortunately)
if the dependencies are missing at build time, and sqlite is one of these.
You should be able to just install libsqlite3-dev,
then rebuild Python and you should be set.
Keep an eye on the build messages,
as they do report which modules they are skipping due to missing dependencies.
Thanks to minrk for pointing me in the right direction. All I had to do was rebuild python. I've outlined the steps below for those that are using pythonbrew. Notice that I already installed the libsqlite3-dev package up in the question section.
First, with the proper version of python and virtual environment loaded up run the command:
$ pip freeze -l > requirements.txt
This gives us a text file list of all of the pip packages that have been installed in the virtual environment for this particular python release in pythonbrew. Then we remove the version of python from pythonbrew and reinstall it (this is the "rebuild python" step):
$ pythonbrew uninstall 2.7.3
$ pythonbrew install 2.7.3
After that, we switch over to the newly installed python version 2.7.3 and create a new virtual environment (which I've called "sci"):
$ pythonbrew switch 2.7.3
$ pythonbrew venv create sci
$ pythonbrew venv use sci
Ideally you should be able to run the command:
$ pip install -r requirements.txt
and according to this pip should reinstall all the modules that you had in the virtual environment before we clobbered that version of python (2.7.3). It didn't work for me for whatever reason so I manually installed all of the modules using pip individuality.
$ ipython --pylab
Python 2.7.3 (default, Jan 5 2013, 18:48:27)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
and IPython history works!
What worked for me (using osx + homebrew + brewed python):
# Reinstall Python 2.7 with sqlite
brew remove python
brew install readline sqlite gdbm --universal
brew install python --universal --framework
# Reinstall iPython with correct bindings
pip uninstall ipython
pip install ipython
And you should be good to go.
You should rebuild your python with sqlite support
sudo apt-get install libsqlite3-dev
wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz
tar -xvf Python-2.7.15.tgz
cd Python-2.7.15
./configure
make
sudo make install
Recreate your virtual environment and you should be good to go
rmvirtualenv venv
mkvirtualenv -p python2 venv
workon venv
pip install -r requirements.txt
# or
pip install ipython
This warning appears on macOS when python is installed with pyenv. By default it installs python without sqlite. These commands reinstall python with sqlite support:
pyenv uninstall 3.7
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.7

How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard?

Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:
noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/bsddb/__init__.py", line 51, in <module>
import _bsddb
ImportError: No module named _bsddb
nice, huh? How do I fix this without giving up and installing/configuring/maintaining my own Python package as per TMNC's suggestion or using MacPorts etc?
Edit
I've gone around the problem by installing Python2.4 and BSDDB via MacPorts.
My question still stands: why is the default install broken and is it possible to fix it.
Follow the instructions at http://marc-abramowitz.com/archives/2007/11/28/hacking-os-xs-python-dbhash-and-bsddb-modules-to-work/ .
The patch did not work for me and I had to replace the bsddb folder in
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
with the bsddb3 in:
/usr/local/lib/python2.7/site-packages/bsddb3
Make sure you backup the bsddb folder just in case.
This pain persists on OSX 10.8. I could not install bsddb3 using macports py-bsddb3 into a virtualenv. What was very simple and did work is:
install db53 from macports
download and unpack bsddb3 source (https://pypi.python.org/pypi/bsddb3/6.1.0)
sudo python setup.py –berkeley-db-incdir=/opt/local/include/db53 –berkeley-db-libdir=/opt/local/lib/db53 install
A solution I found was to install ActivePython, dig into its library (located in /Library/Frameworks/Python.framework/Versions/....your version here..../lib) and copy and paste the _bsddb.so file into my OS X 10.6 native python 2.6 install directory (/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/).
That fixed the missing _bsddb issue leaving me with a working version of bsddb in my native python install. Then, I just uninstalled ActivePython (instructions here)
The error I had was "No module named _bsddb". It turn out I didn't need to upgrade my bsddb. I wasusing the .pkl file created in windows. After renaming the pkl file to get it out the way Mac OSX Python recreated a new .pkl.db file and now it works perfectly.

Categories