Install tkinter and python locally - python

I work with linux on a servies. And I don't have the root privilege. I installed the python-3.2.3 locally to "/home/sam/install_sam". when I import the tkinter module. I get the following error:
ImportError: No module named _tkinter, please install the python-tk package
I know I need to install the Tkinter module. because I don't have the root privilege. I can't use like the following commands:
apt-get install python-tk
sudo apt-get install python-tk
And I search on goolge. I get tcl/tk from here. I install them use the following commands.
cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/tcl
make
make install
cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/tk
--with- tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install
cd ~/Downloads/Python3.2.3/
export LD_LIBRARY_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
export LD_RUN_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
./configure --prefix=/home/sam/install_sam/python
make
make install
I still got error: INFO: Can't locate Tcl/Tk libs and/or headers. How should I config the tcl/tk for the python

Use CPPFLAGS environment variable to set the include directories for tcl and tk before building Python 3. This has worked for me.
export CPPFLAGS="-I/home/sam/install_sam/tcl/include -I/home/sam/install_sam/tk/include"

Finally. I install tcl/tk and python in a same path. It can work now. the commands as follow:
cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/python3
make
make install
cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/python3
--with-tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install
export LD_LIBRARY_PATH=/home/sam/install_sam/python3/lib
cd ~/Downloads/Python3.2.3/3
./configure --prefix=/home/sam/install_sam/python3
make
make install
someone can tell me how to config the tcl/tk for python in the first way(mentioned in the question). I'll appreciate it

sudo apt-get install tcl-dev tk-dev
worked for me, although I ended up pulling a docker image and using that instead.

In my case I had import tkinter properly working on my Python3 environment, but I had to use a pre-compiled Python with its own environment (Blender fyi) that didn't include the dependencies (I needed tkinter to run matplotlib).
The fix in my case was very simple:
In the working python, import tkinter and check where it is installed with tkinter.__file__. This will be something like path/to/site-packages/tkinter
Copy the tkinter folder into the site-packagesof your target installation
Then import _tkinter won't work. Again using the file trick, locate the missing .so file, in my Ubuntu was something like `path/to/python3.7/lib-dynload/_tkinter.cpython-37m-x86_64-linux-gnu.so'
Again, copy the .so file into the corresponding lib-dynload of your target installation. Make sure that both origin and target Python versions are compatible.
To make sure that your target python finds the copied files, make sure that the destination paths are listed under sys.path.
Hope this helps!
Cheers,
Andres

For CentOS, this is:
yum install -y tcl-devel tk-devel
Worked on CentOS 7.
In general, I find that where RHEL has *-dev, CentOS has *-devel

Related

Problems with setting up a configuration file and running a code

I'm fairly new to linux and trying to get some code to run. After trying for a few days without success, I hope someone can help me. My Linux version is
Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial
The code is found here: https://bitbucket.org/dsign/gecmi/wiki/Home
My problems lie in modifying the configuration file: site_config.py from which the developers say I should:
Check this file and edit it in such a way that it matches your build environment, the targets you want to compile and where do you want to install them.
Firstly, I tried to install boost,itbb, scons and numpy/scipy library via apt-get
sudo apt-get install libboost-dev
sudo apt-get install scons
sudo apt-get install python-scipy
sudo apt-get install python-numpy
sudo apt-get install libtbb-dev
I'm not sure if those are the correct versions, but that's what I could find after researching a bit.
The next step is to adapt the entries in the configuration file, but I find it very difficult (actually I have not much of a clue) to find out WHERE all those directories are after installing the above-mentioned libraries are or how to adapt this configuration file respectively:
# Use 'release' for speed, 'debug' for debugging.
COMPILE_MODE='release'
# Use one or both of the following words: 'standalone' for
# building the standalone executable, 'python' for building
# the python module
COMPILE_TARGETS='standalone python'
# Where the boost library is installed. I expect an 'include'
# and a 'lib' dir below.
BOOST_ROOT='/opt/boost_1_47_0/'
# The prefix of the python installation. This is used for deducing
# include directories and lib path of python
PYTHON_PREFIX="/usr/"
# The python's version. Used for deducing include directories and
# library name of python.
PYTHON_VERSION ="2.7"
# Where the Intel threading building blocks is installed. I expect
# and 'include' and a 'lib' directory below this one.
TBB_PREFIX="/home/alcides/programming/projects/sci_python/prx"
# The executable for the c++ compiler to use.
COMPILER_NAME="g++-4.6"
# The place where numpy is installed. I expect the directories
# 'core/include' and 'numarray/include' below.
NUMPY_PREFIX="/usr/local/lib/python2.7/dist-packages/numpy/"
# Where you sould like the standalone program to be installed
GECMI_PROGRAM_INSTALL_AT='/usr/local/bin'
# Where you would like the shared library to be installed. This
# library is used by both the python module and the standalone
# program.
GECMI_LIB_INSTALL_AT='/usr/local/lib'
# Where would you like to have the module installed, for the
# target 'InstallPythonModule'. A dll file called gecmi.{dllext}
# is installed there.
PYTHON_MODULE_INSTALL_AT='/usr/lib/python2.7/dist-packages'
The tip of the authors points to modifying the LD_LIBRARY_PATH variable, but didn't help me much either:
You can get messages of the kind error while loading shared libraries if the dependencies are not correctly installed. In that case, you might want to fiddle with the commands locate and the environment variable LD_LIBRARY_PATH, or the equivalents in your operating system of choice.
I tried to use whereis and locate, but not sure if that works. For example when I use whereis boost or locate boost I find a lot of directories, but no directory like boost/include or boost/lib which seems to be expected by the config file. For numpy there is no numarray/include folder asf.
So basically I was wondering how a linux power user would find all the necessary paths and directories and figure out how to get this code to run (or if some of you could run the code). I'm also thankful for some further information/tutorial/advices on how to get more familiar with solving such problems.
thanks!
in terminal write following commands
sudo apt-get update
sudo apt-get -y upgrade
python3 -V (out put is Python 3.5.2 may be or other version..)
sudo apt-get install -y python3-pip
pip3 install package_name
sudo apt-get install build-essential libssl-dev libffi-dev python-dev
sudo apt-get install -y python3-venv
for more help refer these site
https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-ubuntu-16-04

Linux Mint 17 tkinter not installed

I was trying to run a program that I have been making and ran into a problem with tkinter not being installed, as when I try to run my script in pycharm I get this error: ImportError: No module named '_tkinter', pleaseinstall the python3-tk package`
So I searched on here and found a solution and entered these commands:
sudo apt-get install python-support
sudo update-python-modules -a
which didn't work so I tried:
sudo apt-get install python3-tk
which was tagged as the answer on this question but it threw this error at me:
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
Being pretty new to linux and the terminal, I am completely clueless as to how to do this.
I am using python 3.5 and just want to install tkinter so I can run this script, also before anyone asks yes I have imported tkinter and not Tkinter.
sudo apt-get install python3-tk is the correct way to install tkinter for Python 3 on Linux. However, you interrupted apt while it was installing. To fix the errors, run the command the error message suggested and then install tkinter.
sudo dpkg --configure -a
sudo apt-get install python3-tk
Then you can add from tkinter import *, import tkinter as tk or import tkinter to the beginning of your program depending on how you want to use it. You may also be interested in installing idle-python3.4.
Next time you need to install something just open the software manager from Menu, search for the program and install it :-)
Well when all logic fails- panic. Look for the illogical. I found that I was not running Python 3. My text editor is Geany, and reverts everything to run its default, which was set at Python 2. That included #!.
So, change the defaults in Geany:
Build > Set build commands > then in the dialogs replace every instance of Python with Python3

missing module sqlite3 on python 3.5 [duplicate]

I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:
File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
Looking at the Python install, it gives the same error:
Python 2.5.2 (r252:60911, May 12 2009, 07:46:31)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] 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 "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
>>>
Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included. Do I need to reinstall Python, or is there another way to get this module up and running?
It seems your makefile didn't include the appropriate .so file. You can correct this problem with the steps below:
Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install
Note
The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. If you run this command on your workstation, you'll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall.
I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I've installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.
I had the same problem with Python 3.5 on Ubuntu while using pyenv.
If you're installing the python using pyenv, it's listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version with
pyenv install <python-version>
Then recreate virtualenv if needed.
my python is build from source, the cause is missing options when exec configure
python version:3.7.4
./configure --enable-loadable-sqlite-extensions --enable-optimizations
make
make install
fixed
This is what I did to get it to work.
I am using pythonbrew(which is using pip) with python 2.7.5 installed.
I first did what Zubair(above) said and ran this command:
sudo apt-get install libsqlite3-dev
Then I ran this command:
pip install pysqlite
This fixed the database problem and I got confirmation of this when I ran:
python manager.py syncdb
Install the sqlite-devel package:
yum install sqlite-devel -y
Recompile python from the source:
./configure
make
make altinstall
I found lots of people meet this problem because the Multi-version Python,
on my own vps (cent os 7 x64), I solved it in this way:
Find the file "_sqlite3.so"
find / -name _sqlite3.so
out: /usr/lib64/python2.7/lib-dynload/_sqlite3.so
Find the dir of python Standard library you want to use,
for me /usr/local/lib/python3.6/lib-dynload
Copy the file:
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
Finally, everything will be ok.
For Python 3.7.8 with Redhat 7 or Centos 7.
Install sqlite-devel
$ yum install sqlite-devel
Compile and install Python3 with sqllite extensions
$ ./configure --enable-optimizations --enable-loadable-sqlite-extensions
$ make install
My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so. Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.
Try the following:
find /usr/local -name _sqlite3.so
If the file isn't found, something may be wrong with your Python installation. If it is, make sure the path it's installed to is in the Python path. In the Python shell,
import sys
print sys.path
In my case, /usr/lib/python2.5/lib-dynload is in the list, so it's able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.
I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. Came across similar problems to this thread. I mamaged to fix it by:
Adjusting the setup.py file to include the correct sqlite dev path. Code snippet from setup.py:
def sqlite_incdir:
sqlite_dirs_to_check = [
os.path.join(sqlite_incdir, '..', 'lib64'),
os.path.join(sqlite_incdir, '..', 'lib'),
os.path.join(sqlite_incdir, '..', '..', 'lib64'),
os.path.join(sqlite_incdir, '..', '..', 'lib'),
'/usr/lib/x86_64-linux-gnu/'
]
With the bit that I added being '/usr/lib/x86_64-linux-gnu/'.
After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly :P ), but after running make install, sqlite3 still did not import with the same "ImportError: No module named _sqlite3" whe running "import sqlite3".
So, the library was compiled, but not moved to the correct installation path, so I copied the .so file (cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).
Voila! SQLite3 support now works.
This worked for me in Redhat Centos 6.5:
yum install sqlite-devel
pip install pysqlite
sqlite3 ships with Python. I also had the same problem, I just uninstalled python3.6 and installed it again.
Uninstall existing python:
sudo apt-get remove --purge python3.6
Install python3.6:
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall
Is the python-pysqlite2 package installed?
sudo apt-get install python-pysqlite2
Checking your settings.py file.
Did you not just write "sqlite" instead of "sqlite3" for the database engine?
Putting answer for anyone who lands on this page searching for a solution for Windows OS:
You have to install pysqlite3 or db-sqlite3 if not already installed. you can use following to install.
pip install pysqlite3
pip install db-sqlite3
For me the issue was with DLL file of sqlite3.
Solution:
I took DLL file from sqlite site. This might vary based on your
version of python installation.
I pasted it in the DLL directory of
the env. for me it was "C:\Anaconda\Lib\DLLs", but check for yours.
I have the problem in FreeBSD 8.1:
- No module named _sqlite3 -
It is solved by stand the port ----------
/usr/ports/databases/py-sqlite3
after this one can see:
OK ----------
'>>>' import sqlite3 -----
'>>>' sqlite3.apilevel -----
'2.0'
you must be in centos or redhat and compile python yourself,
it is python‘s bug
do this in your python source code dir and do this below
curl -sk https://gist.github.com/msabramo/2727063/raw/59ea097a1f4c6f114c32f7743308a061698b17fd/gistfile1.diff | patch -p1
I was disappointed this issue still exist till today. As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it. The way I had to resolve it in my case is as follow:
Install SQLite3 from scratch with the proper prefix
Make clean my Python Installation
Run Make install to reinstall Python
As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension. I have end up capturing the steps I used to fix the issue and put it in a separate blog post at:
http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html
I hope this helpful, as while the tips above had helped me get to a solution, I had to combine few of them and modify them a bit.
i got the same problem, nothing worked for me from the above ans
but now i fixed it by
just remove python.pip and sqlite3 and reinstall
sudo apt-get remove python.pip
sudo apt-get remove sqlite3
now install it again
sudo apt-get install python.pip
sudo apt-get install sqlite3
in my case while installing sqlite3 again it showed some error
then i typed
sqlite3
on terminal to check if it was removed or not and it started unpacking it
once the sqlite3 is installed
fireup terminal and write
sqlite3
database.db (to create a database)
i'm sure this will definately help you
Try installing sqlite like this if you are using FreeBSD.
pkg install py27-sqlite3-2.7.10_6
I had the same problem after installing Python 3.8.11 using asdf
To fix the issue:
I had to install libsqlite3-dev
sudo apt-get install libsqlite3-dev
Then uninstall Python via asdf
asdf uninstall python 3.8.11
And install Python again via asdf
asdf install python 3.8.11
The following worked for Python 3.9 with a virtual environment:
Install the sqlite3 library.
sudo apt-get install libsqlite3-dev
Activate the Python virtual environment.
source env/bin/activate
Copy the sqlite3 file into the Python virtual environment and rename it to support Python 3.9.
cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages
mv ./env/lib/python3.9/site-packages/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages/_sqlite3.cpython-39-x86_64-linux-gnu.so
Note, we're renaming 38 to 39 in the file name to support Python 3.9.
Download sqlite3:
wget http://www.sqlite.org/2016/sqlite-autoconf-3150000.tar.gz
Follow these steps to install:
$tar xvfz sqlite-autoconf-3071502.tar.gz
$cd sqlite-autoconf-3071502
$./configure --prefix=/usr/local
$make install
I faced this issue with multiple python dependent package while setup in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.
Error I got:
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I resolved it by --enable-loadable-sqlite-extensions=yes
1.) First find your python or python version you used for creating virtual env. I have used python3.8
e.g
$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config python
$ cd /usr/bin
$ls
python3.8
python3.8-config
Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version
ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes
OR
ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions
Now, create your virtual env using that python version
e.g
Go the folder where you want to create the virtual env
$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate
Its done, now you can install packages
I ran into this same problem on a NetBSD server. A missing .so file needed to be installed using pkgin. To identify what package to install, I ran
pkgin search sqlite
which had lots of results, including
...
py38-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py38-apsw-3.37.0nb2 Python wrapper for SQLite
py38-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py38-sqlite3-3.8.13nb22 Built-in sqlite support for Python 2.5 and up
py39-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py39-apsw-3.37.0nb2 Python wrapper for SQLite
py39-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py39-sqlite3-3.9.13nb22 Built-in sqlite support for Python 2.5 and up
...
(and other python versions as well). I'm using python 3.9, so py39-sqlite3-3.9.13nb22 was the correct choice in my case. Running
sudo pkgin install py39-sqlite3-3.9.13nb22
fixed the issue for me.
You need to install pysqlite in your python environment:
$ pip install pysqlite
Try copying _sqlite3.so so that Python can find it.
It should be as simple as:
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/
Trust me, try it.

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