python - 导入模块后tensorflow导入报错的解决方法
问题描述
pip install tensorflow
#== import it
import tensorflow as tf
错误:
Traceback (most recent call last):
File "C:\Users\C1Manager\PycharmProjects\pythonProject\dani\comp-vision\ld dataset\try.py", line 1, in <module>
import tensorflow
File "C:\Users\C1Manager\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\__init__.py", line 49, in <module>
from ._api.v2 import __internal__
File "C:\Users\C1Manager\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\__internal__\__init__.py", line 13, in <module>
from . import distribute
File "C:\Users\C1Manager\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\__internal__\distribute\__init__.py", line 10, in <module>
from . import combinations
File "C:\Users\C1Manager\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\_api\v2\__internal__\distribute\combinations\__init__.py", line 27, in <module>
from tensorflow.python.distribute.strategy_combinations import parameter_server_strategy_1worker_2ps_1gpu
ImportError: cannot import name 'parameter_server_strategy_1worker_2ps_1gpu' from 'tensorflow.python.distribute.strategy_combinations' (C:\Users\C1Manager\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\distribute\strategy_combinations.py)
解决方案
看起来 Tensorflow 安装不正确,请卸载现有的 Tensorflow 并按照说明安装新的,
使用画中画
#Install tensorflow using pip virtual env
$pip install virtualenv
$virtualenv tf # tf is virtual env name
$source tf/bin/activate
tf $ pip install tensorflow
tf $ python
>>import tensorflow as tf
>>tf.__version__
2.5.0
使用蟒蛇
1. Set Up Anaconda Environments
conda create --name tf_env python=3
2. Activate the new Environment
source activate tf_env
3. Install Tensorflow
pip install tensorflow
推荐阅读
- node.js - Node.js 集群 - 每个核心 1 个工作人员会减慢主线程速度?
- c# - 将字符串解析为浮点数返回不正确的结果
- php - 自动删除购物车中的缺货商品,然后通知帐户用户 - Woocommerce
- jmeter - jmeter中计算TPS的方法
- firebase - Firebase 函数预部署:忽略文件夹
- c++ - 为什么标准布局类的成员必须具有相同的访问控制?
- ruby - 当顶级目录的名称可能包含全局字符时,递归列出所有路径
- keras - 当我在 keras 中使用 GlobalAveragePooling2D 时如何保持维度
- python - 如何让客户端检测来自服务器的更新数据?
- c++ - 错误:没有用于调用“变量”的匹配函数