python - 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:
- macOS 10.14
- Python 3.6.5
解决方案
好的,我实际上不得不更改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 页面的提示也有很大帮助!
推荐阅读
- python - TypeError:列表索引必须是整数,而不是 str (MAPNIK)
- flutter - 在 Flutter 中推送新页面时,Navigator 堆栈上的页面会重建
- sql - 我可以在 2 个不同的表中但在 Oracle 的相同列上使用相同的索引吗
- python - Pandas 中的 lambda 函数后索引列消失
- ruby - 转义字符串中的单引号并将该字符串插入另一个带有未转义单引号的字符串
- asp.net - 我看到这个错误 ORA-01722: invalid number when I want to insert data to oracle database table
- vhdl - 我们可以在模拟器中强制用户定义数据类型的值吗?
- sql - MS Access - 文本字段返回查询字符串而不是查询结果值
- wpf - 如何从选项卡按钮启用禁用主窗口的菜单项
- c# - 为多个类提供附加功能