一、使用python时在不同环境中可以正常导入各个环境中存在的模块
- 基环境及安装的包:安装了flask模块,未安装bcrypt
D:\xxxxyyyy>conda activate base
(base) D:\xxxxyyyy>conda list
# packages in environment at D:\Anaconda3:
#
# NameVersionBuildChannel
......
flask1.0.2py37_1
......
python3.7.1h8c8aaf0_6
......(base) D:\xxxxyyyy>python
>>> import sys;
sys.executable
'D:\\Anaconda3\\python.exe'
>>> import flask;
flask
>>> import bcrypt
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'bcrypt'
- 虚拟环境及安装的包:未安装flask模块,安装了bcrypt模块
D:\xxxxyyyy>conda activate py2(py2) D:\xxxxyyyy>conda list
# packages in environment at D:\Anaconda3\envs\py2:
#
# NameVersionBuildChannel
bcrypt3.1.6py27h0c8e037_0
......
python2.7.16hcb6e200_0
......(py2) D:\xxxxyyyy>python
>>> import sys;
sys.executable
'D:\\Anaconda3\\envs\\py2\\python.exe'
>>> sys.path
['', 'D:\\Anaconda3\\envs\\py2\\python27.zip', 'D:\\Anaconda3\\envs\\py2\\DLLs', 'D:\\Anaconda3\\envs\\py2\\lib', 'D:\\Anaconda3\\envs\\py2\\lib\\plat-win', 'D:\\Anaconda3\\envs\\py2\\lib\\lib-tk', 'D:\\Anaconda3\\envs\\py2', 'D:\\Anaconda3\\envs\\py2\\lib\\site-packages']>>> import flask
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named flask
>>> import bcrypt;
bcrypt
- 此时python解释器版本已变为虚拟环境中的python2版,可以正常使用该虚拟环境才有的模块bcrypt。系统路径已经变成虚拟环境的路径
- 在基环境中启动jupyter notebook
(base) D:\xxxxyyyy>jupyter notebook
[I 11:40:01.172 NotebookApp] JupyterLab extension loaded from D:\Anaconda3\lib\site-packages\jupyterlab
In [1]:import sys
sys.executable
Out[1]:'D:\\Anaconda3\\python.exe' In [2]:import flask
flask
Out[2]:In [3]:import bcrypt
------
ModuleNotFoundError: No module named 'bcyrpt'
- 在虚拟环境中启动jupyter notebook
(py2) D:\xxxxyyyy>jupyter notebook
[I 11:40:01.172 NotebookApp] JupyterLab extension loaded from D:\Anaconda3\lib\site-packages\jupyterlab
In [1]:import sys
sys.executable
Out[1]:'D:\\Anaconda3\\python.exe' In [1]:sys.path
Out[1]:['D:\\xxxxyyyy',
'D:\\Anaconda3\\python37.zip',
'D:\\Anaconda3\\DLLs',
'D:\\Anaconda3\\lib',
'D:\\Anaconda3',]In [2]:import flask
flask
Out[2]:In [3]:import bcrypt
------
ModuleNotFoundError: No module named 'bcyrpt'
- 发现虚拟环境py2的python解释器仍为基环境的python3版本,虚拟环境中存在的bcrypt模块无法导入。系统路径中没有虚拟环境的路径
- 【anaconda中jupyter notebook无法导入已安装的模块】在py2虚拟环境中也安装上jupyter notebook时,导入正常,路径列表也为py2虚拟环境各个文件夹
推荐阅读
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Python专栏|数据分析的常规流程
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Python绘制小红花
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- python|8. 文件系统——文件的删除、移动、复制过程以及链接文件
- 爬虫|若想拿下爬虫大单,怎能不会逆向爬虫,价值过万的逆向爬虫教程限时分享
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍
- java|微软认真聆听了开源 .NET 开发社区的炮轰( 通过CLI 支持 Hot Reload 功能)