conda虚拟环境中安装ipython
問題:今天安裝了tensorflow,啟動ipython竟然提示如下:
In [1]: import tensorflow as tf --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-1-64156d691fe5> in <module> ----> 1 import tensorflow as tfModuleNotFoundError: No module named 'tensorflow'所以解決的方向有兩個:①tensorflow安裝有問題;②ipython環境有問題。
用python啟動一個shell,導入tensorflow沒有問題,說明tensorflow安裝沒有問題,那就是ipython的問題
查看ipython版本
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.明明是3.5.2版本,怎么會是3.7.1呢,除非這個ipyton啟動的不是本虛擬環境中的python,
(tensorflow) λ which ipython /c/ProgramData/Anaconda3/envs/tensorflow/Scripts/ipython果然是base環境中的ipython,在通過conda list發現本虛擬環境tensorflow中沒有ipython,到此問題就清楚了,虛擬環境tensorflow中沒有ipython,然后就近在base中找到一個ipython就啟動了base中的python了,那么就要在虛擬環境tensorflow中安裝一個ipython,在線安裝很簡單,但是存在無法指定具體python版本問題,所以采用conda install離線安裝。
python環境是3.5.2,所以要找一個可以啟動3.5.2的ipython。
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64/
conda install --use-local ipython-5.1.0-py35_2.tar #結果 ipython 5.1.0 py35_2 <unknown>?再次啟動ipython提示缺包,直接在線裝就行了。
裝完后啟動ipthon,導入tensoflow成功。
(tensorflow) λ ipython Python 3.5.2 | packaged by conda-forge | (default, Jan 19 2017, 15:41:23) [MSC v.1900 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information.IPython 5.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details.In [1]: import tensorflow as tfipython啟動的就是本環境中的python3.5.2,完成。
-----------------------------------------------------------------------------------------------------
后來發現直接在當前的虛擬環境中conda install ipython即可安裝當前環境的ipython,前面是比較笨的方式。
總結
以上是生活随笔為你收集整理的conda虚拟环境中安装ipython的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python生成日历_使用Python实
- 下一篇: 阅读jdk源码