Opened 12 years ago
Closed 7 years ago
#38560 closed defect (worksforme)
opencv +python27: cannot import Python module
Reported by: | johnsankey@… | Owned by: | macports-tickets@… |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | ports | Version: | 2.1.3 |
Keywords: | Cc: | jyrkiwahlstedt | |
Port: | opencv |
Description (last modified by larryv (Lawrence Velázquez))
sudo port selfupdate sudo port install python27 py27-numpy py27-scipy sudo port install opencv +python27
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
then contains linkages for numpy and scipy but nothing for opencv so the linkage doesn't work.
.........
I'm told that this fixes the problem with Homebrew: cv2.so and cv.py are located in "/usr/local/Cellar/opencv/2.4.4a/lib/python2.7/site-packages" You need to copy those two files into the python site-packages directory which should be "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/"
I'm also told that this fixes it with Windows: "Copy the file cv2.pyd and paste it into C:\Python27\Lib\site-packages." It is located in C:\Python27\Lib\site-packages\opencv\build\python\2.7
The Macports linkage seems too complex for a quick solution, but is there one?
Attachments (1)
Change History (22)
comment:4 Changed 12 years ago by larryv (Lawrence Velázquez)
Description: | modified (diff) |
---|---|
Resolution: | → invalid |
Status: | new → closed |
comment:5 Changed 12 years ago by larryv (Lawrence Velázquez)
Port: | opencv added |
---|
comment:6 follow-up: 7 Changed 12 years ago by johnsankey@…
Why doesn't the method I used get MacPort's Python 2.7? My understanding is that sudo port can only do that. I have never even heard of numpy or scipy before issuing the commands I list above. Besides, when I repeat sudo port install opencv +python27 it scans everything and announces that everything is fine. All I know is that the Python 2.7 that I got via the commands above doesn't work.
If something I don't know about sneaked the /Library files in, how do I uninstall everything to do with python,numpy,scipy and opencv? Then, what commands do I need to use so that I get solely MacPorts stuff?
comment:7 follow-up: 8 Changed 12 years ago by larryv (Lawrence Velázquez)
sudo port install python27
will get you MacPorts’ Python.
What does port contents py27-numpy
say? I just installed py27-numpy
and everything is under /opt/local
; see my attachment.
Changed 12 years ago by larryv (Lawrence Velázquez)
Attachment: | py27-numpy.contents.txt added |
---|
comment:8 follow-up: 9 Changed 12 years ago by johnsankey@…
What does
port contents py27-numpy
say? I just installedpy27-numpy
and everything is under/opt/local
; see my attachment.
Yes, everything is under /opt/local, for py27-numpy, py27-scipy, opencv and python27. But I still get
python Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import numpy >>> import scipy >>> import opencv Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named opencv
So it seems I'm getting Apple's Python with 'set python python27', not the MacPorts Python. What directory is MacPorts' Python27 in? (I assume specifying directory in set will work.)
BTW, I've been double-clicking on a .py file - it brings up Idle and then (Apple) python. Is any change needed in additional to specifying path in set for this to get Macports' python27?
comment:9 follow-up: 10 Changed 12 years ago by larryv (Lawrence Velázquez)
Replying to johnsankey@…:
So it seems I'm getting Apple's Python with 'set python python27', not the MacPorts Python.
I assume you mean port select
. port set
is a shortcut for port setrequested
. What is the output of port select --list python
?
Can you import the OpenCV module if you start the interpreter using /opt/local/bin/python2.7
?
What directory is MacPorts' Python27 in? (I assume specifying directory in set will work.)
No, that is not how port select
works.
BTW, I've been double-clicking on a .py file - it brings up Idle and then (Apple) python. Is any change needed in additional to specifying path in set for this to get Macports' python27?
I don’t know which application is your default for .py
files, but you can select a different Build Applet.app
or IDLE.app
or Python Launcher.app
through Finder’s Get Info panel, as usual.
comment:10 follow-up: 11 Changed 12 years ago by johnsankey@…
Replying to larryv@…:
Replying to johnsankey@…:
So it seems I'm getting Apple's Python with 'set python python27', not the MacPorts Python.
I assume you mean
port select
.port set
is a shortcut forport setrequested
. What is the output ofport select --list python
?
No. I meant "set python python27" issued at the command prompt, which is what I was told to do in the installation instructions for opencv. Now I've tried
sudo port select --set python python27
and it gives the same thing.
Can you import the OpenCV module if you start the interpreter using
/opt/local/bin/python2.7
?
No, I get the same Apple python as before, and import opencv fails as it did before.
port select --list python gives: Available versions for python: none python25-apple python26-apple python27 (active)
My Finder info window says default for .py is idle, but it doesn't give me the option of which idle, it just gives me the one linked to the Apple python.
comment:11 follow-up: 12 Changed 12 years ago by larryv (Lawrence Velázquez)
Replying to johnsankey@…:
No. I meant "set python python27" issued at the command prompt, which is what I was told to do in the installation instructions for opencv.
I can only conclude that those instructions were wrong. For me, port set
does not do the same thing as port select --set
.
Can you import the OpenCV module if you start the interpreter using
/opt/local/bin/python2.7
?No, I get the same Apple python as before, and import opencv fails as it did before.
What do these commands output?
which python ls -l /opt/local/bin/python{,2.7}
My Finder info window says default for .py is idle, but it doesn't give me the option of which idle, it just gives me the one linked to the Apple python.
Do you have an /Applications/MacPorts/Python 2.7
folder? What’s in it?
comment:12 follow-up: 13 Changed 12 years ago by johnsankey@…
Replying to larryv@…:
I can only conclude that those instructions were wrong. For me,
port set
does not do the same thing asport select --set
.
Fair enough - I've forwarded your comment to the web page author.
What do these commands output?
which python ls -l /opt/local/bin/python{,2.7}
unknown-c8-2a-14-0e-69-42:~ john$ which python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python
unknown-c8-2a-14-0e-69-42:~ john$ ls -l /opt/local/bin/python{,2.7} lrwxr-xr-x 1 root admin 24 28 Mar 08:13 /opt/local/bin/python -> /opt/local/bin/python2.7 lrwxr-xr-x 1 root admin 73 28 Mar 04:59 /opt/local/bin/python2.7 -> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 unknown-c8-2a-14-0e-69-42:~ john$
Do you have an
/Applications/MacPorts/Python 2.7
folder? What’s in it?
/Applications/MacPorts/Python 2.7 contents:
Build Applet.app 2011-07-29 360 KB
IDLE.app 2011-07-29 393 KB
Python Launcher.app 2011-07-29 582 KB
I should note that I need python 2.7 for Quantum GIS that was installed with Apple's mpkg. Somehow Opencv and QGIS have to co-exist.
comment:13 Changed 12 years ago by larryv (Lawrence Velázquez)
Resolution: | invalid |
---|---|
Status: | closed → reopened |
We should probably bring in the maintainer.
comment:14 Changed 12 years ago by larryv (Lawrence Velázquez)
Owner: | changed from macports-tickets@… to stromnov@… |
---|---|
Status: | reopened → new |
Summary: | port install opencv +python27 fails → opencv +python27: cannot import Python module |
comment:15 follow-up: 16 Changed 12 years ago by johnsankey@…
Further to the above: I've found that typing python at the command line opens MacPorts python27 that has opencv attached. However, the idle in that framework (/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle) is an alias of Apple's idle; it only deals with Apple Python27 that doesn't have opencv attached.
Can I persuade MacPorts to install its own idle in this framework? Hopefully, MacPorts idle will deal with MacPorts python27, then I should be able to associate MacPorts idle with .py and use it that way.
comment:16 Changed 12 years ago by larryv (Lawrence Velázquez)
Replying to johnsankey@…:
Further to the above: I've found that typing python at the command line opens MacPorts python27 that has opencv attached. However, the idle in that framework (/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle) is an alias of Apple's idle; it only deals with Apple Python27 that doesn't have opencv attached.
I don’t know what to make of this. Your setup sounds really broken. This what I see:
% port -v installed python27 The following ports are currently installed: python27 @2.7.3_1 (active) platform='darwin 12' archs='x86_64' % ls -l /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle lrwxr-xr-x 1 root wheel 5B Nov 17 22:55 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle@ -> idle2 % ls -l /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle2 lrwxr-xr-x 1 root wheel 7B Nov 17 22:55 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle2@ -> idle2.7 % ls -l /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7 -rwxr-xr-x 1 root wheel 148B Nov 17 22:55 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7* % cat /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7 #!/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 from idlelib.PyShell import main if __name__ == '__main__': main() %
comment:17 Changed 12 years ago by johnsankey@…
Sorry - should have added that the last above was after changing
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
in .profile to
PATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
At least it gets me the python with opencv installed.
port -v installed python27 The following ports are currently installed: python27 @2.7.3_1+universal (active) platform='darwin 10' archs='i386 x86_64'
Nothing about idle. I've found others who have similar problems with QGIS installed, but others who haven't who are also having problems getting opencv to work. (This is in a Coursera class forum, which only members can see.)
Total PATH is now:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PYTHONPATH is null.
comment:18 Changed 12 years ago by larryv (Lawrence Velázquez)
Can you rebuild Python 2.7 and see if idle
is still an alias?
sudo port -n upgrade --force python27
Also you don’t have to add that framework directory to your PATH if you want MacPorts’ Python to be the default when you run python
. Use port select
.
sudo port select --set python python27
comment:19 follow-up: 20 Changed 12 years ago by johnsankey@…
Port select is a separate issue - I've already been down that route: it gets the first python27 in PATH. In order to use the MacPorts python, its location has to be before the Apple python location in PATH.
This will be about the 4th time I've rebuilt python if I do :-(
Might part of this be a conflict with MacPorts WINE, which also imports and uses python? It's the only other MacPorts thing I've got in my system, and I'll bet it doesn't use Idle.
comment:20 Changed 12 years ago by larryv (Lawrence Velázquez)
Cc: | jwa@… added |
---|---|
Owner: | changed from stromnov@… to macports-tickets@… |
Replying to johnsankey@…:
Port select is a separate issue - I've already been down that route: it gets the first python27 in PATH.
No, it gets MacPorts’ Python 2.7. PATH has nothing to do with it.
Of course, all port select
does is create a symlink at /opt/local/bin/python
(assuming the default MacPorts prefix). As usual, your PATH has to be set up properly to catch it.
This will be about the 4th time I've rebuilt python if I do :-(
I can only conclude that your setup is broken. Try posting to the macports-users mailing list; maybe someone there can provide some insight. If not, then you might try reinstalling MacPorts.
Might part of this be a conflict with MacPorts WINE, which also imports and uses python? It's the only other MacPorts thing I've got in my system, and I'll bet it doesn't use Idle.
wine
doesn’t touch python27
.
(Cc-ing the python27
maintainer.)
comment:21 follow-up: 22 Changed 12 years ago by johnsankey@…
When I issued sudo port select --set python python27 *on my system* it got Apple's python until I put the MacPorts python path ahead of the Apple python path, as described above.
When I installed wine *on my system* with MacPorts, it installed MacPorts python at the same time as a dependency.
I have already uninstalled MacPorts *on my system* and everything in it, then re-installed from scratch. Nothing was changed as a result.
comment:22 Changed 12 years ago by larryv (Lawrence Velázquez)
Replying to johnsankey@…:
When I issued sudo port select --set python python27 *on my system* it got Apple's python until I put the MacPorts python path ahead of the Apple python path, as described above.
I don’t know what to say about that. I tried reproducing by reshuffling my $PATH before using port select
, and it symlinks correctly.
When I installed wine *on my system* with MacPorts, it installed MacPorts python at the same time as a dependency.
Yes, that’s expected. What I mean is that the wine
port does not alter the files installed by the python27
port.
I have already uninstalled MacPorts *on my system* and everything in it, then re-installed from scratch. Nothing was changed as a result.
Well then maybe you should post to the mailing list, as I’ve already suggested.
comment:23 Changed 12 years ago by johnsankey@…
The consensus seems to be that it was the python site Python 2.7 in /Library that was taking over the system from MacPorts. I cleaned it out, reinstalled OSX+X11 to ensure that all Apple pythons are sound (they seem to be), deleted /opt, then reinstalled everything MacPorts from scratch. Now, MacPorts stuff now seems to be properly installed. However, MacPorts IDLE doesn't work, so I've submitted a new ticket for that: #38746.
comment:24 Changed 7 years ago by mf2k (Frank Schima)
Resolution: | → worksforme |
---|---|
Status: | new → closed |
There does not seem to be anything to do here.
Replying to johnsankey@…:
MacPorts does not install anything into
/Library
. If numpy and scipy are there, it is because you installed them yourself. MacPorts keeps Python 2.7 packages in${prefix}/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
.The solution (and only configuration we support) is to use MacPorts’ Python 2.7.