python 和 jupyter notebook 中的模块位置不一致
Inconsistent module location in python and jupyter notebook
由于Python中苹果新的M1芯片与TensorFlow不兼容,我按照网上的一些教程在Miniforge3下搭建了一个环境(这样我们就可以运行 python 在 arm64 而不是 x86_64 中?我不完全理解这里的技巧。)。
按照教程(在 https://medium.com/codex/installing-tensorflow-on-m1-macs-958767a7a4b3),我创建了一个名为 tf
的环境并成功安装了 tensorflow
。我检查了模块是否安装在 miniforge3
文件夹中:
(tf) pokfung@pn-204-145 ~ % which python
/Users/pokfung/miniforge3/envs/tf/bin/python
(tf) pokfung@pn-204-145 ~ % python
Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 06:27:18)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy, tensorflow
>>> print(numpy.__file__)
/Users/pokfung/miniforge3/envs/tf/lib/python3.8/site-packages/numpy/__init__.py
>>> print(tensorflow.__file__)
/Users/pokfung/miniforge3/envs/tf/lib/python3.8/site-packages/tensorflow/__init__.py
但是,当我通过 (tf) pokfung@pn-204-145 ~ % jupyter notebook
启动 Jupyter notebook 时,我发现 notebook 没有从以上目录加载模块:
import numpy
print(numpy.__file__)
# Output of the print statement is:
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/__init__.py
我想知道如何配置 Jupyter notebook 才能在 tf
conda 环境中正确 运行。
Jupyter 在后台运行一个内核,在您的情况下支持 Python,但它会从您的主安装中选择内核,而不是您刚刚安装的虚拟环境。你可以 tell Jupyter which kernel to use - 你试过了吗?
由于Python中苹果新的M1芯片与TensorFlow不兼容,我按照网上的一些教程在Miniforge3下搭建了一个环境(这样我们就可以运行 python 在 arm64 而不是 x86_64 中?我不完全理解这里的技巧。)。
按照教程(在 https://medium.com/codex/installing-tensorflow-on-m1-macs-958767a7a4b3),我创建了一个名为 tf
的环境并成功安装了 tensorflow
。我检查了模块是否安装在 miniforge3
文件夹中:
(tf) pokfung@pn-204-145 ~ % which python
/Users/pokfung/miniforge3/envs/tf/bin/python
(tf) pokfung@pn-204-145 ~ % python
Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 06:27:18)
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy, tensorflow
>>> print(numpy.__file__)
/Users/pokfung/miniforge3/envs/tf/lib/python3.8/site-packages/numpy/__init__.py
>>> print(tensorflow.__file__)
/Users/pokfung/miniforge3/envs/tf/lib/python3.8/site-packages/tensorflow/__init__.py
但是,当我通过 (tf) pokfung@pn-204-145 ~ % jupyter notebook
启动 Jupyter notebook 时,我发现 notebook 没有从以上目录加载模块:
import numpy
print(numpy.__file__)
# Output of the print statement is:
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/__init__.py
我想知道如何配置 Jupyter notebook 才能在 tf
conda 环境中正确 运行。
Jupyter 在后台运行一个内核,在您的情况下支持 Python,但它会从您的主安装中选择内核,而不是您刚刚安装的虚拟环境。你可以 tell Jupyter which kernel to use - 你试过了吗?