udacity / CarND-Term1-Starter-Kit-Test

Files to test the starter kit install.
MIT License
30 stars 72 forks source link

Error at step import cv2 #3

Closed TirelessTinkerer closed 6 years ago

TirelessTinkerer commented 7 years ago

I'm following the CarND to run this test. My system is linux mint 18 (basically the same as Ubuntu16.06), installed Anaconda3-4.3.0-Linux-x86_64.sh

From CarND-Term1-Starter-Kit, in created the environment with command:

conda env create -f environment.yml

After activating the environment and loading the notebook, I ran the cells and got the following error after import cv2

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-72fbbcfe2587> in <module>()
----> 1 import cv2

ImportError: dynamic module does not define module export function (PyInit_cv2)

Can someone help me out from this?

akshatbjain commented 7 years ago

Same case with me! It would be great if someone could help.

domluna commented 7 years ago

It's likely a dynamic library required for opencv2 is missing. This Dockerfile might be helpful in that regard. I think this line might fix it https://github.com/udacity/CarND-Term1-Starter-Kit/blob/master/Dockerfile.cpu#L17, not 100% sure though.

akshatbjain commented 7 years ago

@game-of-drones Found the solution to our problem.

PROBLEM: The reason this was happening was that I had set the PYTHONPATH variable on Ubuntu for some other software in the past. The way Anaconda environments work is that they hard link everything that is installed into the environment. Thus each environment is a completely separate installation of Python and all the packages. By using hard links, this is done efficiently. Thus, there's no need to mess with PYTHONPATH because the Python binary in the environment already searches the site-packages in the environment, and the lib of the environment, and so on.

By setting the PYTHONPATH environment variable we interfere with Anaconda's natural behavior thus forcing it to look for libraries in the paths defined by the PYTHONPATH which is generally set to your local machine paths and not the environment paths.

SOLUTION: Best thing to do would be to go to your .bashrc file and comment/remove the lines that set a PYTHONPATH. However, if you don't want to do that you can always do "unset PYTHONPATH" before activating an environment and everything will work like a charm.

Hope this helps.

mvirgo commented 6 years ago

Closing this since it sounds like it's solved for everyone.