首页 > 解决方案 > python / python3 - how to merge different locations for installed packages of anaconda and python?

问题描述

It seems that I have several version of python installed on same computer, one from them being the anaconda distribution. However certain packages can be imported only with certain version of python. How can we merge all the source of packages:

I succesfully installed opencv and try to import it in a script from Atom with the command import cv2 (1):

ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/cv2.so, 2): Library not loaded: /usr/local/opt/ilmbase/lib/libImath-2_2.12.dylib
  Referenced from: /usr/local/Cellar/opencv/3.4.1_4/lib/libopencv_imgcodecs.3.4.dylib
  Reason: image not found

Importing with command python (the one linked to anaconda)

I went then to the Terminal and called python with $ python

Python 3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13undefined09) 
GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53) on darwin

I then tried to import open cv with import cv2 and got the same error message as in (1) above

Importing with command python3

I then entered import python3 (instead of python), it worked: I got:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 03undefined55) GCC 4.2.1 (Apple 
Inc. build 5666) (dot 3) on darwin

And could execute a script with import cv2

apparently those 2 different command fetch the package from different locations because:$ which python get me /anaconda3/bin/python and $ which python3 gets me /Library/Frameworks/Python.framework/Versions/3.6/bin/python3

As I use Atom as text editor, how can I make Atom to look at the correct place?

Many thanks in advance!

Specifications:

标签: pythonpython-3.xopencvpathanaconda

解决方案


好的,我实际上不得不更改jupyter 内核Path.json文件。首先我检查了jupyter内核列表:

$ jupyter kernelspec list
julia-0.6    /Users/mymac/Library/Jupyter/kernels/julia-0.6
julia-1.0    /Users/mymac/Library/Jupyter/kernels/julia-1.0
python3      /Users/mymac/Library/Jupyter/kernels/python3

然后我cd上面的python路径,我在kernel.json里面找到了文件并打开了它:

{
 "argv": [
  "/path/to/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python"
}

然后,在该文件中,我/path/to/python通过在终端中键入以下内容时得到的 python 路径更改了该行:

$ which python
/Users/mymac/anaconda3/bin/python

重新启动Atom,它终于奏效了!

jupyter的github 页面的提示也有很大帮助!


推荐阅读