OpenCV Install for Pydev in Eclipse using Macports on OsX Mavericks - opencv

I used the following tutorial to install macports and opencv:
http://www.jeffreythompson.org/blog/2012/09/21/installing-opencv-for-python-on-mac-lion/
It works in that after typing "python" I can call "import cv" without errors.
My first question: how do I get this to work with IDLE. I think the issue is via the terminal I'm using Python 2.7.5. IDLE is using Python 2.7.3. If this is the problem, what is the easiest way to fix this.
My second question: how do I get opencv to work in eclipse with pydev? I can't really find much helpful information. I have installed opencv via macports. But I can't get Eclipse to recognize that opencv has been installed. "Import cv" command says no module named cv exists.

I was struggling with this problem today. Here are the steps I followed using macports
Install macports and xcode
Follow Sam Khans post listed here to install python, relink it in your terminal and then install OpenCV:
http://samkhan13.wordpress.com/2012/06/18/using-opencv-with-python-on-your-mac-os-x/
NOTE: At this point you should be able to enter a terminal session and type "python" and then "import cv2" successfully.
Open eclipse and click on "eclipse" then "preferences" in the bar menu at the top of the program.
In the pop-up that appears click the arrow next to "pydev" to expand the menu then click "Interpreter - Python"
Press the "new" button on the right of the window
In the pop-up type in the name for this interpreter (I did python27 for my python2.7 version)
Next link the python executable for the desired version under the macports install tree "/opt/local/bin/pythonX.X" where X.X is your version (i.e. 2.7) and click ok.
A list of the available python libraries should populate. Select only those under the macport install tree (so we don't confuse our interpreter and cross list with another python build)
Finally click OK (which should automatically apply the changes).
The window will compile the interpreter and VOILA Python, Numpy and OpenCV working together through pydev in eclipse.

Related

Problem using opencv in visual studio code

I installed openCV and vsc sees this import. However, when the program executes, an error pops up.
I have no idea where the bug is
make sure you select the right interpreter (or virtual environment)
re-select python interpreter in VSCode
reinstall the opencv library in the right interpreter:
pip3 install --force-reinstall opencv-contrib-python
also, you can use Anaconda to manage your packages

Installing OpenCV into PyCharm

Idk if this is a stackoverflow-appropriate post so forgive if the question is misplaced. I'm trying to install OpenCV into my Pycharm IDE through the conda virtual environment. I typed conda install -c conda-forge opencv inside the PyCharm terminal and it has been doing this for 11 hours and God knows how many more to go.
Pycharm did this with PyTorch as well. Am I doing something wrong or is this normal?
While you can install packages directly in PyCharm by going to file->settings select Project Interpreter and click on the '+' icon on the top right (see image)
I would recommend creating a requirements.txt file in the root of your project, and write down all your required packages. When a package is missing, PyCharm will automatically suggest to install the package for you.
e.g. for installing opencv you can add the following to you requirements.txt
opencv-python
Or even specify the version that your project needs
opencv-python==4.1.2
edit: the advantage of using a requirement.txt is that you can more easily port the project to another machine, and re-install the packages if needed.

How can I restore the traditional console in Spyder?

Recent versions of Spyder have removed the traditional console, and now only include the IPython console. (See https://github.com/spyder-ide/spyder/issues/4524) Is there any way to add it back?
UPDATE: I have accepted the answer given by the Spyder maintainer, which is "No", as it is the answer to the question. The question itself is somewhat inchoate, and I note here that it is possible to just install a previous version of Spyder. The last version with the traditional console is 3.1.4. Anaconda Python makes this fairly easy to install a previous version:
Launch Anaconda Navigator.
Activate the virtual environment in which you wish to install a previous version of Spyder.
On the Home screen, you will see several tools such as IPython, Jupyter, and Spyder.
In the box for Spyder, click the gear icon, "Install specific version", and 3.1.4:
(Spyder maintainer here) No, unfortunately there's no way to add it back again.
We decided to remove it because of all the problems the Python console had, as mentioned in the issue you referenced above in your question.

Import OpenCV in Pycharm [duplicate]

This question already has answers here:
How to install OpenCV on Windows and enable it for PyCharm without using the package manager
(3 answers)
Closed 4 years ago.
I want to use OpenCV (Python module) in pycharm. I set my Python interpreter in settings and added OpenCV path (C:\opencv\build\python\2.7) to the Python interpreter path. Unfortunately pycharm couldn't import OpenCV. It's noticeable that I see the cv2.pyd in the left panel (project panel).
Can anyone help me to resolve this issue ?
Refer to How to install OpenCV on Windows and enable it for PyCharm without using the package manager
Steps to follow:
Install Python 2.7.10
Install Pycharm(If you have not done it already)
Download and install the OpenCV executable.
Add OpenCV in the system path(%OPENCV_DIR% = /path/of/opencv/directory)
Goto C:\opencv\build\python\2.7\x86 folder and copy cv2.pyd file.
Goto C:\Python27\DLLs directory and paste the cv2.pyd file.
Goto C:\Python27\Lib\site-packages directory and paste the cv2.pyd file.
Goto PyCharm IDE and goto DefaultSettings>PythonInterpreter.
Select the Python which you have installed on Step1.
Install the packages numpy,matplotlib and pip in pycharm.
Restart your PyCharm.
PyCharm now has OpenCV library installed and working.
If you have installed pycharm,then you can type :
pip install opencv-python
after satisfied,
then go to file ,setting (in pycharm)
project ,project interpreter,click on plus icon on the top right ,
search opencv-python and install package.

How to start spyder after macports installation

this is my first question to post.
I am working with python at the moment (on mac os 10.6.8), and have struggled for the lack of an ide. I have been using a version of emacs that offers syntax highlighting, but does not offer the ability to browse variable values without print statements. What I was looking for was the equivalent of eclipse, which basically died on my machine when I upgraded from 10.4.11 to 10.6.8. I've not been successful resurrecting it. Time to move on.
My graduate advisor suggested spyder, and last night I bit the bullet, installing macports and (apparently) spyder, successfully.
The problem I'm having is HOW do I start spyder once installed. Apparently, python spyder.py is not the approach to use. Elsewhere (not here) I saw a post that suggested that there was supposed to be a batch executable that I should be able to find by typing
which spyder
This yielded nothing.
The spyder documentation (located at http://packages.python.org/spyder/options.html) suggests that the command
python spyder.py
is the way to go. Here is the result:
Bobs-Machine:spyderlib robertlilly$ python spyder.py
Traceback (most recent call last):
File "spyder.py", line 31, in
from spyderlib import qt #analysis:ignore
ImportError: No module named spyderlib
Most of my searches here have just pointed out that one should use MacPorts for the install, nothing after that. The readme included the macports spyder install, I thought, didn't provide sufficient direction.
If anybody knows where to look, that would be great.
Regards,
Robert
For me, I installed the macports package py37-spyder. In /opt/local/bin there is the package there, spyder-3.7. Launching that works already. In order to make that the default, I have to run
sudo port select --set spyder spyder-37
Then I can run it directly as
spyder from Terminal. If you want to see which versions of spyder are available on your system, then
port select --list spyder
will tell you the versions you have.
Macports should install a spyder binary to /opt/local/bin/spyder, or thereabouts. If you already have /opt/local/bin/ in your PATH variable, then just run:
$ spyder &
Or more explicitly:
$ /opt/local/bin/spyder &
...if you don't have the PATH setup. Hope that helps.
I just recently installed spyder via MacPorts.
(the command I chose was sudo port install py27-spyder, which installed Spyder v.2.2.3 on Mac OS 10.7.5 & Python 2.7.5)
At the end of the Spyder installation, the terminal showed "use command spyder to launch" (or something to that effect)
So, for me, I simply had to type spyder into a terminal to launch it. Your error referring to missing spyderlib might mean that your spyder installation did not in fact complete properly. (I have found it's not uncommon to have to track down 2-3 weird bugs and dependencies for complex MacPorts installs).
If you find it did complete properly, then perhaps the MacPorts directory was not added to your PATH. It you open ~/.profile, you should seen that MacPorts added it's directory to the shell's search path. Here's what the MacPorts installer added to my .profile:
# MacPorts Installer addition on 2012-11-19_at_17:16:31: adding an appropriate PATH variable fo$
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
To make a Mac OS-friendly icon to launch Spyder, I then made a new text file (I did it with Terminal.app>pico) containing the following text:
#!/bin/bash
spyder
and saved the file as spyder.command. This file is now double-clickable and will launch Spyder (and an alias to it can have a more normal name like "Launch Spyder"). Throw it into the /Applications folder & make an Icon for it via /Utilities/Icon Composer.app (grab the Spyder icon on the website) and it's like a Pythonic Matlab!

Resources