
原环境为python3.8,为安装tensorflow 1* ,使用conda 创建python 3.7 的虚拟环境tensorflow1。
激活虚拟环境后,python调用的仍为python 3.8。
问题如下:
python路径正确
(tensorflow1) Rachel1900 (master #) ~
$ which python
/Users/Rachel1900/anaconda3/envs/tensorflow1/bin/python
但执行版本错误,且当前环境下库无法调用
(tensorflow1) Rachel1900 (master #) ~
$ python --version
Python 3.8.5
判断为python运行路径出错
尝试方案conda deactivate 退出conda环境,重新进入需要的环境
多次尝试无果
解决方案参考- Mac修改默认python版本
在~/.bash_profile 中增加虚拟环境的python路径alias python=“python-path”,解决。具体步骤:
- 虚拟环境的python路径查找:
(tensorflow1) Rachel1900 (master #) ~
$ which python
/Users/Rachel1900/anaconda3/envs/tensorflow1/bin/python
- 在根目录下打开
~/.bash_profile
(tensorflow1) Rachel1900 (master #) ~
$ cd ~
(tensorflow1) Rachel1900 (master #) ~
$ open ~/.bash_profile
-
在配置文件增加
alias python="/Users/Rachel1900/anaconda3/envs/tensorflow1/bin/python" -
保存文件后在terminal 运行
(tensorflow1) Rachel1900 (master #) ~
$ source ~/.bash_profile
- 检查python版本
#方法1,直接读取python 版本
(tensorflow1) Rachel1900 (master #) ~
$ python --version
Python 3.7.12
#方法2
(tensorflow1) Rachel1900 (master #) ~
$ python -c"import sys; print(sys.executable)"
/Users/Rachel1900/anaconda3/envs/tensorflow1/bin/python
问题解决
参考-
Create virtual environments for python with conda
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)