一些python代码运行出错解决方法

  1. 同时调用keras和tensorflow出现问题,可能是版本不兼容,一些对应的版本:兼容版本
  2. 当cv2包出现问题ERROR: No matching distribution found for cv2,解决方法为安装opencv:安装方法
  3. tensorflow篇:
    (1) python RuntimeError: tf.placeholder() is not compatible with eager execution.
    错误行前输入tf.compat.v1.disable_eager_execution()
    (2) AttributeError:module tensorflow no attribute app
    将import tensorflow as tf 改为import tensorflow.compat.v1 as tf
    (3) tensorflow在python3.10下使用pycharm安装出错
    直接在该环境下输入pip install tensorflow
    (4) “AttributeError: module ‘tensorflow’ has no attribute ‘random_uniform’”
    It was moved to tf.random.uniform,将random_uniform改为random.uniform
  4. pytorch安装篇
    (1) mac下安装
    (2) windows下安装
  5. umap包出现问题:AttributeError module umap has no attribute UMAP
    要使用UMAP,需要安装umap-learn 而不是umap,可以
pip uninstall umap
pip install umap-learn

再调用umap时,不要再使用import umap,应当使用

import umap.umap_ as umap

另外,如果先使用import umap,再import umap.umap_ as umap也会有问题,直接调用import umap.umap_ as umap不会出错
6. Numpy和Tensor互相转换:可参考
7. AttributeError: ‘RandomOverSampler‘ object has no attribute ‘fit_sample‘:
把代码中的

from imblearn.over_sampling import RandomOverSampler
ROS = RandomOverSampler(random_state=0)
X_resampled, y_resampled = ROS.fit_sample(X, y)

fit_sample改为fit_resample

  1. NotWritableError: The current user does not have write permissions to a required path.解决方案
sudo chown -R xxx anaconda3 
  1. PackagesNotFoundError: The following packages are not available from current channels python=2.7,解决办法
    先查看是否有python2的版本
conda search -f python

有的话, 使用如下解决方案

conda create -c 'https://repo.continuum.io/pkgs/free/osx-64' -n py2 python=2.7
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值